File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -348,6 +348,17 @@ function setLanguage(language: Language) {
348348 editor ?.setOption (' mode' , language )
349349}
350350
351+ function focusEditor() {
352+ isShowCodeImage .value = false
353+ isShowJsonVisualizer .value = false
354+
355+ nextTick (() => {
356+ requestAnimationFrame (() => {
357+ editor ?.focus ()
358+ })
359+ })
360+ }
361+
351362async function format() {
352363 const availableLang: Language [] = [
353364 ' css' ,
@@ -497,7 +508,10 @@ onMounted(() => {
497508 data-editor
498509 class =" grid h-full grid-rows-[auto_1fr_auto] overflow-hidden pt-[var(--content-top-offset)]"
499510 >
500- <EditorHeader v-if =" isShowHeader " />
511+ <EditorHeader
512+ v-if =" isShowHeader "
513+ @focus-editor =" focusEditor "
514+ />
501515 <div
502516 v-show =" isShowEditor"
503517 class =" flex min-h-0 flex-1 flex-col overflow-auto"
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ import {
2525 getEntryNameValidationIssue ,
2626} from ' ~/shared/entryNameValidation'
2727
28+ const emit = defineEmits <{
29+ focusEditor: []
30+ }>()
31+
2832const {
2933 displayedSnippets,
3034 selectedSnippet,
@@ -157,6 +161,20 @@ function onNameBlur() {
157161 isFocusedSnippetName .value = false
158162}
159163
164+ function onNameKeydown(event : KeyboardEvent ) {
165+ if (
166+ (event .key !== ' Enter' && event .key !== ' Tab' )
167+ || event .shiftKey
168+ || nameValidationIssue .value
169+ || hasNameConflict .value
170+ ) {
171+ return
172+ }
173+
174+ event .preventDefault ()
175+ emit (' focusEditor' )
176+ }
177+
160178const isShowJsonVisualizerAction = computed (
161179 () => selectedSnippetContent .value ?.language === ' json' ,
162180)
@@ -235,6 +253,7 @@ function onJsonVisualizerToggle() {
235253 :select =" isFocusedSnippetName "
236254 @focus =" onSnippetNameFocus "
237255 @blur =" onNameBlur "
256+ @keydown =" onNameKeydown "
238257 />
239258 </UiInputValidationTooltip >
240259 </div >
Original file line number Diff line number Diff line change @@ -377,6 +377,16 @@ watch(isDark, () => {
377377 applyExternalState (content .value )
378378})
379379
380+ function focusEditor() {
381+ nextTick (() => {
382+ view ?.focus ()
383+ })
384+ }
385+
386+ defineExpose ({
387+ focusEditor ,
388+ })
389+
380390async function syncNavigationNoteUIStateRegistration(noteId = props .noteId ) {
381391 unregisterNavigationNoteUIState ?.()
382392 unregisterNavigationNoteUIState = undefined
Original file line number Diff line number Diff line change @@ -193,6 +193,8 @@ const isNameValidationTooltipOpen = computed(() => {
193193 return isNameFocused .value && Boolean (nameValidationMessage .value )
194194})
195195
196+ const notesEditorRef = useTemplateRef (' notesEditorRef' )
197+
196198function onNoteNameFocus() {
197199 isNameFocused .value = true
198200 onNameFocus ()
@@ -208,6 +210,24 @@ function onNameBlur() {
208210 isFocusedNoteName .value = false
209211}
210212
213+ function onNameKeydown(event : KeyboardEvent ) {
214+ if (
215+ (event .key !== ' Enter' && event .key !== ' Tab' )
216+ || event .shiftKey
217+ || nameValidationIssue .value
218+ || hasNameConflict .value
219+ ) {
220+ return
221+ }
222+
223+ event .preventDefault ()
224+ hideNotesViewModes ()
225+
226+ nextTick (() => {
227+ notesEditorRef .value ?.focusEditor ()
228+ })
229+ }
230+
211231const editorContent = ref (' ' )
212232// id заметки, контент которой сейчас находится в редакторе: меняется только
213233// вместе с editorContent, когда полная запись уже загружена.
@@ -314,6 +334,7 @@ onBeforeUnmount(() => {
314334 :select =" isFocusedNoteName "
315335 @focus =" onNoteNameFocus "
316336 @blur =" onNameBlur "
337+ @keydown =" onNameKeydown "
317338 />
318339 </UiInputValidationTooltip >
319340 </div >
@@ -366,6 +387,7 @@ onBeforeUnmount(() => {
366387 >
367388 <div class =" min-h-0" >
368389 <NotesEditor
390+ ref="notesEditorRef"
369391 v-model :content =" content "
370392 :mode =" notesEditorMode "
371393 :note-id =" editorNoteId "
You can’t perform that action at this time.
0 commit comments