hotkey: Use "m" hotkey for moving messages.

Fixes #23113.
This commit is contained in:
Sahil Batra 2022-10-13 12:17:36 +05:30 committed by Tim Abbott
parent 10668b080e
commit eed728fb59
7 changed files with 41 additions and 4 deletions

View File

@ -80,7 +80,7 @@ mock_esm("../../static/js/recent_topics_util", {
is_in_focus: () => false, is_in_focus: () => false,
}); });
mock_esm("../../static/js/stream_popover", { const stream_popover = mock_esm("../../static/js/stream_popover", {
stream_popped: () => false, stream_popped: () => false,
topic_popped: () => false, topic_popped: () => false,
all_messages_popped: () => false, all_messages_popped: () => false,
@ -262,7 +262,7 @@ function test_normal_typing() {
run_test("allow normal typing when processing text", ({override, override_rewire}) => { run_test("allow normal typing when processing text", ({override, override_rewire}) => {
// Unmapped keys should immediately return false, without // Unmapped keys should immediately return false, without
// calling any functions outside of hotkey.js. // calling any functions outside of hotkey.js.
assert_unmapped("bfmoyz"); assert_unmapped("bfoyz");
assert_unmapped("BEFHILNOQTWXYZ"); assert_unmapped("BEFHILNOQTWXYZ");
// All letters should return false if we are composing text. // All letters should return false if we are composing text.
@ -336,7 +336,7 @@ run_test("modal open", ({override}) => {
test_normal_typing(); test_normal_typing();
}); });
run_test("misc", () => { run_test("misc", ({override}) => {
// Next, test keys that only work on a selected message. // Next, test keys that only work on a selected message.
const message_view_only_keys = "@+>RjJkKsSuvi:GM"; const message_view_only_keys = "@+>RjJkKsSuvi:GM";
@ -370,6 +370,12 @@ run_test("misc", () => {
assert_mapping(":", reactions, "open_reactions_popover", true); assert_mapping(":", reactions, "open_reactions_popover", true);
assert_mapping(">", compose_actions, "quote_and_reply"); assert_mapping(">", compose_actions, "quote_and_reply");
assert_mapping("e", message_edit, "start"); assert_mapping("e", message_edit, "start");
override(message_edit, "can_move_message", () => true);
assert_mapping("m", stream_popover, "build_move_topic_to_stream_popover");
override(message_edit, "can_move_message", () => false);
assert_unmapped("m");
}); });
run_test("lightbox overlay open", ({override}) => { run_test("lightbox overlay open", ({override}) => {

View File

@ -148,6 +148,7 @@ const keypress_mappings = {
106: {name: "vim_down", message_view_only: true}, // 'j' 106: {name: "vim_down", message_view_only: true}, // 'j'
107: {name: "vim_up", message_view_only: true}, // 'k' 107: {name: "vim_up", message_view_only: true}, // 'k'
108: {name: "vim_right", message_view_only: true}, // 'l' 108: {name: "vim_right", message_view_only: true}, // 'l'
109: {name: "move_message", message_view_only: true}, // 'm'
110: {name: "n_key", message_view_only: false}, // 'n' 110: {name: "n_key", message_view_only: false}, // 'n'
112: {name: "p_key", message_view_only: false}, // 'p' 112: {name: "p_key", message_view_only: false}, // 'p'
113: {name: "query_streams", message_view_only: true}, // 'q' 113: {name: "query_streams", message_view_only: true}, // 'q'
@ -965,6 +966,14 @@ export function process_hotkey(e, hotkey) {
message_edit.start($row); message_edit.start($row);
return true; return true;
} }
case "move_message": {
if (!message_edit.can_move_message(msg)) {
return false;
}
stream_popover.build_move_topic_to_stream_popover(msg.stream_id, msg.topic, msg);
return true;
}
} }
return false; return false;

View File

@ -181,6 +181,21 @@ export function get_deletability(message) {
return false; return false;
} }
export function can_move_message(message) {
if (!page_params.realm_allow_message_editing) {
return false;
}
if (!message.is_stream) {
return false;
}
return (
get_editability(message) !== editability_types.NO ||
settings_data.user_can_move_messages_between_streams()
);
}
export function stream_and_topic_exist_in_edit_history(message, stream_id, topic) { export function stream_and_topic_exist_in_edit_history(message, stream_id, topic) {
/* Checks to see if a stream_id and a topic match any historical /* Checks to see if a stream_id and a topic match any historical
stream_id and topic state in the message's edit history. stream_id and topic state in the message's edit history.

View File

@ -23,6 +23,7 @@
<li> <li>
<a class="popover_move_message" data-message-id="{{message_id}}" tabindex="0"> <a class="popover_move_message" data-message-id="{{message_id}}" tabindex="0">
<i class="fa fa-arrows" aria-hidden="true"></i> {{move_message_menu_item}} <i class="fa fa-arrows" aria-hidden="true"></i> {{move_message_menu_item}}
<span class="hotkey-hint">(m)</span>
</a> </a>
</li> </li>
{{/if}} {{/if}}

View File

@ -1,7 +1,7 @@
{{#if is_content_editable}} {{#if is_content_editable}}
<i class="fa fa-pencil edit_content_button edit_message_button" role="button" tabindex="0" aria-label="{{t 'Edit message' }} (e)" data-tippy-content="{{#tr}}Edit message{{/tr}} (e)"></i> <i class="fa fa-pencil edit_content_button edit_message_button" role="button" tabindex="0" aria-label="{{t 'Edit message' }} (e)" data-tippy-content="{{#tr}}Edit message{{/tr}} (e)"></i>
{{else if can_move_message}} {{else if can_move_message}}
<i class="fa fa-arrows move_message_button edit_message_button" role="button" tabindex="0" aria-label="{{t 'Move message' }} (e)" data-tippy-content="{{#tr}}Move message{{/tr}}"></i> <i class="fa fa-arrows move_message_button edit_message_button" role="button" tabindex="0" aria-label="{{t 'Move message' }} (m)" data-tippy-content="{{#tr}}Move message{{/tr}} (m)"></i>
{{else}} {{else}}
<i class="fa fa-file-code-o view_source_button edit_message_button" role="button" tabindex="0" aria-label="{{t 'View message source' }} (e)" data-tippy-content="{{#tr}}View message source{{/tr}} (e)" data-message-id="{{msg_id}}"></i> <i class="fa fa-file-code-o view_source_button edit_message_button" role="button" tabindex="0" aria-label="{{t 'View message source' }} (e)" data-tippy-content="{{#tr}}View message source{{/tr}} (e)" data-message-id="{{msg_id}}"></i>
{{/if}} {{/if}}

View File

@ -220,6 +220,10 @@
<td class="definition">{{t 'Edit selected message or view message source' }}</td> <td class="definition">{{t 'Edit selected message or view message source' }}</td>
<td><span class="hotkey"><kbd>E</kbd></span></td> <td><span class="hotkey"><kbd>E</kbd></span></td>
</tr> </tr>
<tr id="move-message-hotkey-help">
<td class="definition">{{t 'Move messages or topic' }}</td>
<td><span class="hotkey"><kbd>M</kbd></span></td>
</tr>
<tr> <tr>
<td class="definition">{{t 'Star selected message' }}</td> <td class="definition">{{t 'Star selected message' }}</td>
<td><span class="hotkey"><kbd>Ctrl</kbd> + <kbd>S</kbd></span></td> <td><span class="hotkey"><kbd>Ctrl</kbd> + <kbd>S</kbd></span></td>

View File

@ -145,6 +145,8 @@ below, and add more to your repertoire as needed.
* **Edit message or view message source**: <kbd>E</kbd> * **Edit message or view message source**: <kbd>E</kbd>
* **Move message and (optionally) other messages in the same topic**: <kbd>M</kbd>
* **Star message**: <kbd>Ctrl</kbd> + <kbd>S</kbd> * **Star message**: <kbd>Ctrl</kbd> + <kbd>S</kbd>
* **React with <img alt=":thumbs_up:" class="emoji" * **React with <img alt=":thumbs_up:" class="emoji"