mirror of
				https://github.com/vector-im/element-web.git
				synced 2025-11-04 10:11:03 +01:00 
			
		
		
		
	Merge pull request #3116 from matrix-org/bwindels/feature-guard-arrowup-to-edit
Keep old arrow-up behaviour when editing is not enabled
This commit is contained in:
		
						commit
						cc155ac049
					
				@ -1206,39 +1206,42 @@ export default class MessageComposerInput extends React.Component {
 | 
				
			|||||||
    onVerticalArrow = (e, up) => {
 | 
					    onVerticalArrow = (e, up) => {
 | 
				
			||||||
        if (e.ctrlKey || e.shiftKey || e.metaKey) return;
 | 
					        if (e.ctrlKey || e.shiftKey || e.metaKey) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (e.altKey) {
 | 
					        // selection must be collapsed
 | 
				
			||||||
 | 
					        const selection = this.state.editorState.selection;
 | 
				
			||||||
 | 
					        if (!selection.isCollapsed) return;
 | 
				
			||||||
 | 
					        // and we must be at the edge of the document (up=start, down=end)
 | 
				
			||||||
 | 
					        const document = this.state.editorState.document;
 | 
				
			||||||
 | 
					        if (up) {
 | 
				
			||||||
 | 
					            if (!selection.anchor.isAtStartOfNode(document)) return;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            if (!selection.anchor.isAtEndOfNode(document)) return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const editingEnabled = SettingsStore.isFeatureEnabled("feature_message_editing");
 | 
				
			||||||
 | 
					        const shouldSelectHistory = (editingEnabled && e.altKey) || !editingEnabled;
 | 
				
			||||||
 | 
					        const shouldEditLastMessage = editingEnabled && !e.altKey && up;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (shouldSelectHistory) {
 | 
				
			||||||
            // Try select composer history
 | 
					            // Try select composer history
 | 
				
			||||||
            const selected = this.selectHistory(up);
 | 
					            const selected = this.selectHistory(up);
 | 
				
			||||||
            if (selected) {
 | 
					            if (selected) {
 | 
				
			||||||
                // We're selecting history, so prevent the key event from doing anything else
 | 
					                // We're selecting history, so prevent the key event from doing anything else
 | 
				
			||||||
                e.preventDefault();
 | 
					                e.preventDefault();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else if (!e.altKey && up) {
 | 
					        } else if (shouldEditLastMessage) {
 | 
				
			||||||
            // Try edit the latest message
 | 
					            const editEvent = findEditableEvent(this.props.room, false);
 | 
				
			||||||
            const selection = this.state.editorState.selection;
 | 
					            if (editEvent) {
 | 
				
			||||||
 | 
					                // We're selecting history, so prevent the key event from doing anything else
 | 
				
			||||||
            // selection must be collapsed
 | 
					                e.preventDefault();
 | 
				
			||||||
            if (!selection.isCollapsed) return;
 | 
					                dis.dispatch({
 | 
				
			||||||
            const document = this.state.editorState.document;
 | 
					                    action: 'edit_event',
 | 
				
			||||||
 | 
					                    event: editEvent,
 | 
				
			||||||
            // and we must be at the edge of the document (up=start, down=end)
 | 
					                });
 | 
				
			||||||
            if (!selection.anchor.isAtStartOfNode(document)) return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!e.altKey) {
 | 
					 | 
				
			||||||
                const editEvent = findEditableEvent(this.props.room, false);
 | 
					 | 
				
			||||||
                if (editEvent) {
 | 
					 | 
				
			||||||
                    // We're selecting history, so prevent the key event from doing anything else
 | 
					 | 
				
			||||||
                    e.preventDefault();
 | 
					 | 
				
			||||||
                    dis.dispatch({
 | 
					 | 
				
			||||||
                        action: 'edit_event',
 | 
					 | 
				
			||||||
                        event: editEvent,
 | 
					 | 
				
			||||||
                    });
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    selectHistory = async (up) => {
 | 
					    selectHistory = (up) => {
 | 
				
			||||||
        const delta = up ? -1 : 1;
 | 
					        const delta = up ? -1 : 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // True if we are not currently selecting history, but composing a message
 | 
					        // True if we are not currently selecting history, but composing a message
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user