Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
b4d20079
Commit
b4d20079
authored
Jul 08, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow any earlier message to be edited.
updates #421
parent
a9bb99a1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
33 deletions
+149
-33
dist/converse.js
dist/converse.js
+50
-16
spec/messages.js
spec/messages.js
+56
-0
src/converse-chatview.js
src/converse-chatview.js
+43
-17
No files found.
dist/converse.js
View file @
b4d20079
...
...
@@ -70210,9 +70210,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
if (ev.keyCode === KEY.ENTER) {
this.onFormSubmitted(ev);
} else if (ev.keyCode === KEY.UP_ARROW && !ev.target.selectionEnd) {
this.edit
Previous
Message();
this.edit
Earlier
Message();
} else if (ev.keyCode === KEY.DOWN_ARROW && ev.target.selectionEnd === ev.target.value.length) {
this.
cancelMessageCorrection
();
this.
editLaterMessage
();
} else if (ev.keyCode !== KEY.FORWARD_SLASH && this.model.get('chat_state') !== _converse.COMPOSING) {
// Set chat state to composing if keyCode is not a forward-slash
// (which would imply an internal command and not a message).
...
...
@@ -70220,19 +70220,53 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}
},
cancelMessageCorrection() {
this.insertIntoTextArea('', true);
this.model.messages.where('correcting').forEach(msg => msg.save('correcting', false));
editLaterMessage() {
let message;
let idx = this.model.messages.findLastIndex('correcting');
if (idx >= 0) {
this.model.messages.at(idx).save('correcting', false);
while (idx < this.model.messages.length - 1) {
idx += 1;
if (this.model.messages.at(idx).get('message')) {
message = this.model.messages.at(idx);
break;
}
}
}
if (message) {
this.insertIntoTextArea(message.get('message'), true);
message.save('correcting', true);
} else {
this.insertIntoTextArea('', true);
}
},
editPreviousMessage() {
const msg = _.findLast(this.model.messages.models, msg => msg.get('message'));
editEarlierMessage() {
let message;
let idx = this.model.messages.findLastIndex('correcting');
if (idx >= 0) {
this.model.messages.at(idx).save('correcting', false);
while (idx > 0) {
idx -= 1;
if (this.model.messages.at(idx).get('message')) {
message = this.model.messages.at(idx);
break;
}
}
}
if (msg) {
this.insertIntoTextArea(msg.get('message'), true); // We don't set "correcting" the Backbone-way, because
// we don't want it to persist to storage.
message = message || _.findLast(this.model.messages.models, msg => msg.get('message'));
msg.save('correcting', true);
if (message) {
this.insertIntoTextArea(message.get('message'), true);
message.save('correcting', true);
}
},
...
...
@@ -70260,21 +70294,21 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
},
insertIntoTextArea(value, replace = false) {
const text
box_el
= this.el.querySelector('.chat-textarea');
const text
area
= this.el.querySelector('.chat-textarea');
if (replace) {
text
box_el
.value = value;
text
area
.value = value;
} else {
let existing = text
box_el
.value;
let existing = text
area
.value;
if (existing && existing[existing.length - 1] !== ' ') {
existing = existing + ' ';
}
text
box_el
.value = existing + value + ' ';
text
area
.value = existing + value + ' ';
}
text
box_el
.focus();
text
area
.focus();
},
createEmojiPicker() {
spec/messages.js
View file @
b4d20079
...
...
@@ -106,6 +106,62 @@
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
false
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
textarea
.
value
=
'
It is the east, and Juliet is the one.
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
2
);
textarea
.
value
=
'
Arise, fair sun, and kill the envious moon
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
3
);
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
38
// Up arrow
});
expect
(
textarea
.
value
).
toBe
(
'
Arise, fair sun, and kill the envious moon
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBe
(
true
);
textarea
.
selectionEnd
=
0
;
// Happens by pressing up,
// but for some reason not in tests, so we set it manually.
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
38
// Up arrow
});
expect
(
textarea
.
value
).
toBe
(
'
It is the east, and Juliet is the one.
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBeFalsy
();
textarea
.
value
=
'
It is the east, and Juliet is the sun.
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
textarea
.
value
).
toBe
(
''
);
const
messages
=
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
);
expect
(
messages
.
length
).
toBe
(
3
);
expect
(
messages
[
0
].
querySelector
(
'
.chat-msg-text
'
).
textContent
)
.
toBe
(
'
But soft, what light through yonder window breaks?
'
);
expect
(
messages
[
1
].
querySelector
(
'
.chat-msg-text
'
).
textContent
)
.
toBe
(
'
It is the east, and Juliet is the sun.
'
);
expect
(
messages
[
2
].
querySelector
(
'
.chat-msg-text
'
).
textContent
)
.
toBe
(
'
Arise, fair sun, and kill the envious moon
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBeFalsy
();
done
();
}));
...
...
src/converse-chatview.js
View file @
b4d20079
...
...
@@ -919,9 +919,9 @@
if
(
ev
.
keyCode
===
KEY
.
ENTER
)
{
this
.
onFormSubmitted
(
ev
);
}
else
if
(
ev
.
keyCode
===
KEY
.
UP_ARROW
&&
!
ev
.
target
.
selectionEnd
)
{
this
.
edit
Previous
Message
();
this
.
edit
Earlier
Message
();
}
else
if
(
ev
.
keyCode
===
KEY
.
DOWN_ARROW
&&
ev
.
target
.
selectionEnd
===
ev
.
target
.
value
.
length
)
{
this
.
cancelMessageCorrection
();
this
.
editLaterMessage
();
}
else
if
(
ev
.
keyCode
!==
KEY
.
FORWARD_SLASH
&&
this
.
model
.
get
(
'
chat_state
'
)
!==
_converse
.
COMPOSING
)
{
// Set chat state to composing if keyCode is not a forward-slash
// (which would imply an internal command and not a message).
...
...
@@ -929,18 +929,44 @@
}
},
cancelMessageCorrection
()
{
this
.
insertIntoTextArea
(
''
,
true
);
this
.
model
.
messages
.
where
(
'
correcting
'
).
forEach
(
msg
=>
msg
.
save
(
'
correcting
'
,
false
));
editLaterMessage
()
{
let
message
;
let
idx
=
this
.
model
.
messages
.
findLastIndex
(
'
correcting
'
);
if
(
idx
>=
0
)
{
this
.
model
.
messages
.
at
(
idx
).
save
(
'
correcting
'
,
false
);
while
(
idx
<
this
.
model
.
messages
.
length
-
1
)
{
idx
+=
1
;
if
(
this
.
model
.
messages
.
at
(
idx
).
get
(
'
message
'
))
{
message
=
this
.
model
.
messages
.
at
(
idx
);
break
;
}
}
}
if
(
message
)
{
this
.
insertIntoTextArea
(
message
.
get
(
'
message
'
),
true
);
message
.
save
(
'
correcting
'
,
true
);
}
else
{
this
.
insertIntoTextArea
(
''
,
true
);
}
},
editPreviousMessage
()
{
const
msg
=
_
.
findLast
(
this
.
model
.
messages
.
models
,
(
msg
)
=>
msg
.
get
(
'
message
'
));
if
(
msg
)
{
this
.
insertIntoTextArea
(
msg
.
get
(
'
message
'
),
true
);
// We don't set "correcting" the Backbone-way, because
// we don't want it to persist to storage.
msg
.
save
(
'
correcting
'
,
true
);
editEarlierMessage
()
{
let
message
;
let
idx
=
this
.
model
.
messages
.
findLastIndex
(
'
correcting
'
);
if
(
idx
>=
0
)
{
this
.
model
.
messages
.
at
(
idx
).
save
(
'
correcting
'
,
false
);
while
(
idx
>
0
)
{
idx
-=
1
;
if
(
this
.
model
.
messages
.
at
(
idx
).
get
(
'
message
'
))
{
message
=
this
.
model
.
messages
.
at
(
idx
);
break
;
}
}
}
message
=
message
||
_
.
findLast
(
this
.
model
.
messages
.
models
,
(
msg
)
=>
msg
.
get
(
'
message
'
));
if
(
message
)
{
this
.
insertIntoTextArea
(
message
.
get
(
'
message
'
),
true
);
message
.
save
(
'
correcting
'
,
true
);
}
},
...
...
@@ -961,17 +987,17 @@
},
insertIntoTextArea
(
value
,
replace
=
false
)
{
const
text
box_el
=
this
.
el
.
querySelector
(
'
.chat-textarea
'
);
const
text
area
=
this
.
el
.
querySelector
(
'
.chat-textarea
'
);
if
(
replace
)
{
text
box_el
.
value
=
value
;
text
area
.
value
=
value
;
}
else
{
let
existing
=
text
box_el
.
value
;
let
existing
=
text
area
.
value
;
if
(
existing
&&
(
existing
[
existing
.
length
-
1
]
!==
'
'
))
{
existing
=
existing
+
'
'
;
}
text
box_el
.
value
=
existing
+
value
+
'
'
;
text
area
.
value
=
existing
+
value
+
'
'
;
}
text
box_el
.
focus
()
text
area
.
focus
()
},
createEmojiPicker
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment