From 61b3aaafd269f3db2d5349a18ebb8af9d3fb869b Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 8 Jun 2020 11:42:29 -0400 Subject: [PATCH] Autofocus new note descriptions in the UI code instead of the mode code (re: #7680) --- modules/modes/add_note.js | 4 ---- modules/modes/select_note.js | 2 +- modules/ui/note_editor.js | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/modes/add_note.js b/modules/modes/add_note.js index fa924d505..b257663cd 100644 --- a/modules/modes/add_note.js +++ b/modules/modes/add_note.js @@ -34,10 +34,6 @@ export function modeAddNote(context) { context .selectedNoteID(note.id) .enter(modeSelectNote(context, note.id).newFeature(true)); - - // autofocus the description field - context.container() - .select('.sidebar textarea.new-comment-input').node().focus(); } diff --git a/modules/modes/select_note.js b/modules/modes/select_note.js index 7a22496a3..d8f6cbd9f 100644 --- a/modules/modes/select_note.js +++ b/modules/modes/select_note.js @@ -117,7 +117,7 @@ export function modeSelectNote(context, selectedNoteID) { selectNote(); var sidebar = context.ui().sidebar; - sidebar.show(_noteEditor.note(note)); + sidebar.show(_noteEditor.note(note).newNote(_newFeature)); // expand the sidebar, avoid obscuring the note if needed sidebar.expand(sidebar.intersects(note.extent())); diff --git a/modules/ui/note_editor.js b/modules/ui/note_editor.js index f6d0adac9..f16a71339 100644 --- a/modules/ui/note_editor.js +++ b/modules/ui/note_editor.js @@ -31,6 +31,7 @@ export function uiNoteEditor(context) { // var formFields = uiFormFields(context); var _note; + var _newNote; // var _fieldsArr; @@ -75,7 +76,6 @@ export function uiNoteEditor(context) { .call(noteComments.note(_note)) .call(noteSaveSection); - var footer = selection.selectAll('.footer') .data([0]); @@ -152,7 +152,7 @@ export function uiNoteEditor(context) { return _note.isNew() ? t('note.newDescription') : t('note.newComment'); }); - noteSaveEnter + var commentTextarea = noteSaveEnter .append('textarea') .attr('class', 'new-comment-input') .attr('placeholder', t('note.inputPlaceholder')) @@ -163,6 +163,11 @@ export function uiNoteEditor(context) { .on('input.note-input', changeInput) .on('blur.note-input', changeInput); + if (_newNote) { + // autofocus the comment field for new notes + commentTextarea.node().focus(); + } + // update noteSave = noteSaveEnter .merge(noteSave) @@ -430,6 +435,12 @@ export function uiNoteEditor(context) { return noteEditor; }; + noteEditor.newNote = function(val) { + if (!arguments.length) return _newNote; + _newNote = val; + return noteEditor; + }; + return utilRebind(noteEditor, dispatch, 'on'); }