Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
18d9a7fd
Commit
18d9a7fd
authored
6 years ago
by
Thibaut Girka
Browse files
Options
Downloads
Patches
Plain Diff
Fix caret position after inserting suggestions (fixes #281)
parent
d8793e1b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/javascript/flavours/glitch/features/composer/index.js
+5
-6
5 additions, 6 deletions
app/javascript/flavours/glitch/features/composer/index.js
app/javascript/flavours/glitch/reducers/compose.js
+7
-1
7 additions, 1 deletion
app/javascript/flavours/glitch/reducers/compose.js
with
12 additions
and
7 deletions
app/javascript/flavours/glitch/features/composer/index.js
+
5
−
6
View file @
18d9a7fd
...
...
@@ -56,6 +56,7 @@ function mapStateToProps (state) {
advancedOptions
:
state
.
getIn
([
'
compose
'
,
'
advanced_options
'
]),
amUnlocked
:
!
state
.
getIn
([
'
accounts
'
,
me
,
'
locked
'
]),
focusDate
:
state
.
getIn
([
'
compose
'
,
'
focusDate
'
]),
caretPosition
:
state
.
getIn
([
'
compose
'
,
'
caretPosition
'
]),
isSubmitting
:
state
.
getIn
([
'
compose
'
,
'
is_submitting
'
]),
isUploading
:
state
.
getIn
([
'
compose
'
,
'
is_uploading
'
]),
layout
:
state
.
getIn
([
'
local_settings
'
,
'
layout
'
]),
...
...
@@ -117,7 +118,6 @@ const handlers = {
handleEmoji
(
data
)
{
const
{
textarea
:
{
selectionStart
}
}
=
this
;
const
{
onInsertEmoji
}
=
this
.
props
;
this
.
caretPos
=
selectionStart
+
data
.
native
.
length
+
1
;
if
(
onInsertEmoji
)
{
onInsertEmoji
(
selectionStart
,
data
);
}
...
...
@@ -139,7 +139,6 @@ const handlers = {
// Selects a suggestion from the autofill.
handleSelect
(
tokenStart
,
token
,
value
)
{
const
{
onSelectSuggestion
}
=
this
.
props
;
this
.
caretPos
=
null
;
if
(
onSelectSuggestion
)
{
onSelectSuggestion
(
tokenStart
,
token
,
value
);
}
...
...
@@ -191,7 +190,6 @@ class Composer extends React.Component {
assignHandlers
(
this
,
handlers
);
// Instance variables.
this
.
caretPos
=
null
;
this
.
textarea
=
null
;
}
...
...
@@ -220,11 +218,11 @@ class Composer extends React.Component {
// everyone else from the conversation.
componentDidUpdate
(
prevProps
)
{
const
{
caretPos
,
textarea
,
}
=
this
;
const
{
focusDate
,
caretPosition
,
isSubmitting
,
preselectDate
,
text
,
...
...
@@ -238,8 +236,8 @@ class Composer extends React.Component {
selectionStart
=
text
.
search
(
/
\s
/
)
+
1
;
selectionEnd
=
text
.
length
;
break
;
case
!
isNaN
(
caretPos
)
&&
caretPos
!==
null
:
selectionStart
=
selectionEnd
=
caretPos
;
case
!
isNaN
(
caretPos
ition
)
&&
caretPos
ition
!==
null
:
selectionStart
=
selectionEnd
=
caretPos
ition
;
break
;
default
:
selectionStart
=
selectionEnd
=
text
.
length
;
...
...
@@ -396,6 +394,7 @@ Composer.propTypes = {
advancedOptions
:
ImmutablePropTypes
.
map
,
amUnlocked
:
PropTypes
.
bool
,
focusDate
:
PropTypes
.
instanceOf
(
Date
),
caretPosition
:
PropTypes
.
number
,
isSubmitting
:
PropTypes
.
bool
,
isUploading
:
PropTypes
.
bool
,
layout
:
PropTypes
.
string
,
...
...
This diff is collapsed.
Click to expand it.
app/javascript/flavours/glitch/reducers/compose.js
+
7
−
1
View file @
18d9a7fd
...
...
@@ -56,6 +56,7 @@ const initialState = ImmutableMap({
privacy
:
null
,
text
:
''
,
focusDate
:
null
,
caretPosition
:
null
,
preselectDate
:
null
,
in_reply_to
:
null
,
is_submitting
:
false
,
...
...
@@ -148,6 +149,7 @@ function continueThread (state, status) {
map
.
update
(
'
media_attachments
'
,
list
=>
list
.
clear
());
map
.
set
(
'
idempotencyKey
'
,
uuid
());
map
.
set
(
'
focusDate
'
,
new
Date
());
map
.
set
(
'
caretPosition
'
,
null
);
map
.
set
(
'
preselectDate
'
,
new
Date
());
});
}
...
...
@@ -159,7 +161,6 @@ function appendMedia(state, media) {
map
.
update
(
'
media_attachments
'
,
list
=>
list
.
push
(
media
));
map
.
set
(
'
is_uploading
'
,
false
);
map
.
set
(
'
resetFileKey
'
,
Math
.
floor
((
Math
.
random
()
*
0x10000
)));
map
.
set
(
'
focusDate
'
,
new
Date
());
map
.
set
(
'
idempotencyKey
'
,
uuid
());
if
(
prevSize
===
0
&&
(
state
.
get
(
'
default_sensitive
'
)
||
state
.
get
(
'
spoiler
'
)))
{
...
...
@@ -187,6 +188,7 @@ const insertSuggestion = (state, position, token, completion) => {
map
.
set
(
'
suggestion_token
'
,
null
);
map
.
update
(
'
suggestions
'
,
ImmutableList
(),
list
=>
list
.
clear
());
map
.
set
(
'
focusDate
'
,
new
Date
());
map
.
set
(
'
caretPosition
'
,
position
+
completion
.
length
+
1
);
map
.
set
(
'
idempotencyKey
'
,
uuid
());
});
};
...
...
@@ -197,6 +199,7 @@ const insertEmoji = (state, position, emojiData) => {
return
state
.
withMutations
(
map
=>
{
map
.
update
(
'
text
'
,
oldText
=>
`
${
oldText
.
slice
(
0
,
position
)}${
emoji
}
\u200B
${
oldText
.
slice
(
position
)}
`
);
map
.
set
(
'
focusDate
'
,
new
Date
());
map
.
set
(
'
caretPosition
'
,
position
+
emoji
.
length
+
1
);
map
.
set
(
'
idempotencyKey
'
,
uuid
());
});
};
...
...
@@ -278,6 +281,7 @@ export default function compose(state = initialState, action) {
map
=>
map
.
merge
(
new
ImmutableMap
({
do_not_federate
:
/👁
\u
fe0f
?\u
200b
?(?:
<
\/
p>
)?
$/
.
test
(
action
.
status
.
get
(
'
content
'
))
}))
);
map
.
set
(
'
focusDate
'
,
new
Date
());
map
.
set
(
'
caretPosition
'
,
null
);
map
.
set
(
'
preselectDate
'
,
new
Date
());
map
.
set
(
'
idempotencyKey
'
,
uuid
());
...
...
@@ -325,6 +329,7 @@ export default function compose(state = initialState, action) {
return
state
.
withMutations
(
map
=>
{
map
.
update
(
'
text
'
,
text
=>
[
text
.
trim
(),
`@
${
action
.
account
.
get
(
'
acct
'
)}
`
].
filter
((
str
)
=>
str
.
length
!==
0
).
join
(
'
'
));
map
.
set
(
'
focusDate
'
,
new
Date
());
map
.
set
(
'
caretPosition
'
,
null
);
map
.
set
(
'
idempotencyKey
'
,
uuid
());
});
case
COMPOSE_DIRECT
:
...
...
@@ -332,6 +337,7 @@ export default function compose(state = initialState, action) {
map
.
update
(
'
text
'
,
text
=>
[
text
.
trim
(),
`@
${
action
.
account
.
get
(
'
acct
'
)}
`
].
filter
((
str
)
=>
str
.
length
!==
0
).
join
(
'
'
));
map
.
set
(
'
privacy
'
,
'
direct
'
);
map
.
set
(
'
focusDate
'
,
new
Date
());
map
.
set
(
'
caretPosition
'
,
null
);
map
.
set
(
'
idempotencyKey
'
,
uuid
());
});
case
COMPOSE_SUGGESTIONS_CLEAR
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment