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
45d14406
Commit
45d14406
authored
Aug 10, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cancel message correction by pressing escape.
Also fixes #1153
parent
4c86cca2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
19 deletions
+83
-19
dist/converse.js
dist/converse.js
+42
-9
src/converse-chatview.js
src/converse-chatview.js
+41
-10
No files found.
dist/converse.js
View file @
45d14406
...
...
@@ -69428,9 +69428,15 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
const u = converse.env.utils;
const KEY = {
ENTER: 13,
SHIFT: 17,
CTRL: 17,
ALT: 18,
ESCAPE: 27,
UP_ARROW: 38,
DOWN_ARROW: 40,
FORWARD_SLASH: 47
FORWARD_SLASH: 47,
META: 91,
META_RIGHT: 93
};
converse.plugins.add('converse-chatview', {
/* Plugin dependencies are other plugins which might be
...
...
@@ -70296,17 +70302,31 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
keyPressed(ev) {
/* Event handler for when a key is pressed in a chat box textarea.
*/
if (ev.shiftKey) {
if (ev.ctrlKey) {
// When ctrl is pressed, no chars are entered into the textarea.
return;
}
if (ev.keyCode === KEY.ENTER) {
this.onFormSubmitted(ev);
} else if (ev.keyCode === KEY.UP_ARROW && !ev.target.selectionEnd) {
this.editEarlierMessage();
} else if (ev.keyCode === KEY.DOWN_ARROW && ev.target.selectionEnd === ev.target.value.length) {
this.editLaterMessage();
} else if (ev.keyCode !== KEY.FORWARD_SLASH && this.model.get('chat_state') !== _converse.COMPOSING) {
if (!ev.shiftKey && !ev.altKey) {
if (ev.keyCode === KEY.FORWARD_SLASH) {
// Forward slash is used to run commands. Nothing to do here.
return;
} else if (ev.keyCode === KEY.ESCAPE) {
return this.onEscapePressed(ev);
} else if (ev.keyCode === KEY.ENTER) {
return this.onFormSubmitted(ev);
} else if (ev.keyCode === KEY.UP_ARROW && !ev.target.selectionEnd) {
return this.editEarlierMessage();
} else if (ev.keyCode === KEY.DOWN_ARROW && ev.target.selectionEnd === ev.target.value.length) {
return this.editLaterMessage();
}
}
if (_.includes([KEY.SHIFT, KEY.META, KEY.META_RIGHT, KEY.ESCAPE, KEY.ALT], ev.keyCode)) {
return;
}
if (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).
this.setChatState(_converse.COMPOSING);
...
...
@@ -70319,7 +70339,20 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}));
},
onEscapePressed(ev) {
ev.preventDefault();
const idx = this.model.messages.findLastIndex('correcting'),
message = idx >= 0 ? this.model.messages.at(idx) : null;
if (message) {
message.save('correcting', false);
}
this.insertIntoTextArea('', true, false);
},
onMessageEditButtonClicked(ev) {
ev.preventDefault();
const idx = this.model.messages.findLastIndex('correcting'),
currently_correcting = idx >= 0 ? this.model.messages.at(idx) : null,
message_el = u.ancestor(ev.target, '.chat-msg'),
src/converse-chatview.js
View file @
45d14406
...
...
@@ -52,9 +52,15 @@
const
u
=
converse
.
env
.
utils
;
const
KEY
=
{
ENTER
:
13
,
SHIFT
:
17
,
CTRL
:
17
,
ALT
:
18
,
ESCAPE
:
27
,
UP_ARROW
:
38
,
DOWN_ARROW
:
40
,
FORWARD_SLASH
:
47
FORWARD_SLASH
:
47
,
META
:
91
,
META_RIGHT
:
93
};
converse
.
plugins
.
add
(
'
converse-chatview
'
,
{
...
...
@@ -915,15 +921,28 @@
keyPressed
(
ev
)
{
/* Event handler for when a key is pressed in a chat box textarea.
*/
if
(
ev
.
shiftKey
)
{
return
;
}
if
(
ev
.
keyCode
===
KEY
.
ENTER
)
{
this
.
onFormSubmitted
(
ev
);
}
else
if
(
ev
.
keyCode
===
KEY
.
UP_ARROW
&&
!
ev
.
target
.
selectionEnd
)
{
this
.
editEarlierMessage
();
}
else
if
(
ev
.
keyCode
===
KEY
.
DOWN_ARROW
&&
ev
.
target
.
selectionEnd
===
ev
.
target
.
value
.
length
)
{
this
.
editLaterMessage
();
}
else
if
(
ev
.
keyCode
!==
KEY
.
FORWARD_SLASH
&&
this
.
model
.
get
(
'
chat_state
'
)
!==
_converse
.
COMPOSING
)
{
if
(
ev
.
ctrlKey
)
{
// When ctrl is pressed, no chars are entered into the textarea.
return
;
}
if
(
!
ev
.
shiftKey
&&
!
ev
.
altKey
)
{
if
(
ev
.
keyCode
===
KEY
.
FORWARD_SLASH
)
{
// Forward slash is used to run commands. Nothing to do here.
return
;
}
else
if
(
ev
.
keyCode
===
KEY
.
ESCAPE
)
{
return
this
.
onEscapePressed
(
ev
);
}
else
if
(
ev
.
keyCode
===
KEY
.
ENTER
)
{
return
this
.
onFormSubmitted
(
ev
);
}
else
if
(
ev
.
keyCode
===
KEY
.
UP_ARROW
&&
!
ev
.
target
.
selectionEnd
)
{
return
this
.
editEarlierMessage
();
}
else
if
(
ev
.
keyCode
===
KEY
.
DOWN_ARROW
&&
ev
.
target
.
selectionEnd
===
ev
.
target
.
value
.
length
)
{
return
this
.
editLaterMessage
();
}
}
if
(
_
.
includes
([
KEY
.
SHIFT
,
KEY
.
META
,
KEY
.
META_RIGHT
,
KEY
.
ESCAPE
,
KEY
.
ALT
],
ev
.
keyCode
))
{
return
;
}
if
(
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).
this
.
setChatState
(
_converse
.
COMPOSING
);
...
...
@@ -934,7 +953,19 @@
return
f
(
this
.
model
.
messages
.
filter
({
'
sender
'
:
'
me
'
}));
},
onEscapePressed
(
ev
)
{
ev
.
preventDefault
();
const
idx
=
this
.
model
.
messages
.
findLastIndex
(
'
correcting
'
),
message
=
idx
>=
0
?
this
.
model
.
messages
.
at
(
idx
)
:
null
;
if
(
message
)
{
message
.
save
(
'
correcting
'
,
false
);
}
this
.
insertIntoTextArea
(
''
,
true
,
false
);
},
onMessageEditButtonClicked
(
ev
)
{
ev
.
preventDefault
();
const
idx
=
this
.
model
.
messages
.
findLastIndex
(
'
correcting
'
),
currently_correcting
=
idx
>=
0
?
this
.
model
.
messages
.
at
(
idx
)
:
null
,
message_el
=
u
.
ancestor
(
ev
.
target
,
'
.chat-msg
'
),
...
...
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