Skip to content

Commit

Permalink
Codemirror Vim :w comamnd: submit correct form
Browse files Browse the repository at this point in the history
Closes gh-1098
  • Loading branch information
inducer committed Oct 17, 2024
1 parent 546c9a7 commit 3d7a04e
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions relate/static/js/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,20 @@ export function setListener(view, fn) {
});
}

Vim.defineEx('write', 'w', () => {
// assume we're submitting the changes, reset the change flag
anyEditorChangedFlag = false;

const textarea = document.querySelector('textarea.rl-managed-by-codemirror');
if (textarea.form) {
const { form } = textarea;

Vim.defineEx('write', 'w', (cm) => {
const form = cm.cm6.dom.closest('form');
if (form) {
// prefer 'submit' over 'save' on flow pages
let submitButton = form.querySelector("input[type='submit'][name='submit']");
if (submitButton) {
submitButton.click();
anyEditorChangedFlag = false;
return;
}

submitButton = form.querySelector("input[type='submit']");
if (submitButton) {
anyEditorChangedFlag = false;
submitButton.click();
}
}
Expand Down

0 comments on commit 3d7a04e

Please sign in to comment.