From e9487c904cc444a46ee913b3763344783bf49da1 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Wed, 9 Oct 2024 13:40:37 +0200 Subject: [PATCH 1/4] Add next/previous glyph --- src/fontra/client/lang/en.json | 2 ++ src/fontra/client/lang/zh-CN.json | 2 ++ src/fontra/views/editor/editor.js | 46 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/src/fontra/client/lang/en.json b/src/fontra/client/lang/en.json index 4c96e8524..249b3a9d5 100644 --- a/src/fontra/client/lang/en.json +++ b/src/fontra/client/lang/en.json @@ -136,7 +136,9 @@ "menubar.view.find-glyphs-that-use": "Find glyphs that use '%0'", "menubar.view.remove-selected-glyph-from-canvas": "Remove selected glyph from canvas", "menubar.view.replace-selected-glyph-on-canvas": "Replace selected glyph on canvas", + "menubar.view.select-next-glyph": "Select next glyph", "menubar.view.select-next-source": "Select next source", + "menubar.view.select-previous-glyph": "Select previous glyph", "menubar.view.select-previous-source": "Select previous source", "selection.none": "(No selection)", "sidebar.designspace-navigation": "Designspace Navigation", diff --git a/src/fontra/client/lang/zh-CN.json b/src/fontra/client/lang/zh-CN.json index 8ef1d4e4f..29428e972 100644 --- a/src/fontra/client/lang/zh-CN.json +++ b/src/fontra/client/lang/zh-CN.json @@ -136,7 +136,9 @@ "menubar.view.find-glyphs-that-use": "寻找使用了 '%0' 的字符形", "menubar.view.remove-selected-glyph-from-canvas": "Remove selected glyph from canvas", "menubar.view.replace-selected-glyph-on-canvas": "Replace selected glyph on canvas", + "menubar.view.select-next-glyph": "Select next glyph", "menubar.view.select-next-source": "选择下一个源", + "menubar.view.select-previous-glyph": "Select previous glyph", "menubar.view.select-previous-source": "选择上一个源", "selection.none": "(未选择)", "sidebar.designspace-navigation": "Designspace 导航", diff --git a/src/fontra/views/editor/editor.js b/src/fontra/views/editor/editor.js index dce76400c..6201531f5 100644 --- a/src/fontra/views/editor/editor.js +++ b/src/fontra/views/editor/editor.js @@ -497,6 +497,26 @@ export class EditorController { () => this.doSelectPreviousNextSource(false) ); + registerAction( + "action.select-previous-glyph", + { + topic, + titleKey: "menubar.view.select-previous-glyph", + defaultShortCuts: [{ baseKey: "ArrowLeft", commandKey: true }], + }, + () => this.doSelectPreviousNextGlyph(true) + ); + + registerAction( + "action.select-next-glyph", + { + topic, + titleKey: "menubar.view.select-next-glyph", + defaultShortCuts: [{ baseKey: "ArrowRight", commandKey: true }], + }, + () => this.doSelectPreviousNextGlyph(false) + ); + registerAction( "action.find-glyphs-that-use", { @@ -1549,6 +1569,12 @@ export class EditorController { this.glyphSelectedContextMenuItems.push({ actionIdentifier: "action.select-next-source", }); + this.glyphSelectedContextMenuItems.push({ + actionIdentifier: "action.select-previous-glyph", + }); + this.glyphSelectedContextMenuItems.push({ + actionIdentifier: "action.select-next-glyph", + }); this.glyphSelectedContextMenuItems.push({ title: () => translate( @@ -2804,6 +2830,26 @@ export class EditorController { this.sceneSettings.selectedSourceIndex = newSourceIndex; } + async doSelectPreviousNextGlyph(selectPrevious) { + const glyphNames = Object.keys(this.fontController.glyphMap); + const selectedGlyphName = this.sceneSettings.selectedGlyphName; + if (!selectedGlyphName) { + return; + } + const index = glyphNames.indexOf(selectedGlyphName); + + const newIndex = selectPrevious + ? index - 1 < 0 + ? glyphNames.length - 1 + : index - 1 + : index + 1 >= glyphNames.length + ? 0 + : index + 1; + + const glyphInfo = this.fontController.glyphInfoFromGlyphName(glyphNames[newIndex]); + this.insertGlyphInfos([glyphInfo], 0, true); + } + async doFindGlyphsThatUseGlyph() { const glyphName = this.sceneSettings.selectedGlyphName; From 1ed1c3185846d1578dc790bdfe8123ea2171d53e Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Thu, 10 Oct 2024 12:38:29 +0200 Subject: [PATCH 2/4] Use filteredGlyphItems for Next/Previous Glyph --- src/fontra/client/web-components/glyphs-search.js | 1 + src/fontra/views/editor/editor.js | 4 +++- src/fontra/views/editor/panel-glyph-search.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fontra/client/web-components/glyphs-search.js b/src/fontra/client/web-components/glyphs-search.js index 7663d2893..9f2b4e958 100644 --- a/src/fontra/client/web-components/glyphs-search.js +++ b/src/fontra/client/web-components/glyphs-search.js @@ -151,6 +151,7 @@ export class GlyphsSearch extends UnlitElement { const filteredGlyphItems = this.glyphsListItems.filter( this._glyphNamesListFilterFunc ); + this.filteredGlyphItems = filteredGlyphItems; this.glyphNamesList.setItems(filteredGlyphItems); } } diff --git a/src/fontra/views/editor/editor.js b/src/fontra/views/editor/editor.js index 6201531f5..79462ad5b 100644 --- a/src/fontra/views/editor/editor.js +++ b/src/fontra/views/editor/editor.js @@ -2831,7 +2831,9 @@ export class EditorController { } async doSelectPreviousNextGlyph(selectPrevious) { - const glyphNames = Object.keys(this.fontController.glyphMap); + const filteredGlyphItems = this.fontController.glyphsSearch.filteredGlyphItems; + const glyphNames = filteredGlyphItems.map((x) => x.glyphName); + const selectedGlyphName = this.sceneSettings.selectedGlyphName; if (!selectedGlyphName) { return; diff --git a/src/fontra/views/editor/panel-glyph-search.js b/src/fontra/views/editor/panel-glyph-search.js index 98d673d9d..8503e4b39 100644 --- a/src/fontra/views/editor/panel-glyph-search.js +++ b/src/fontra/views/editor/panel-glyph-search.js @@ -26,6 +26,7 @@ export default class GlyphSearchPanel extends Panel { glyphsSearch.updateGlyphNamesListContent(); }); this.editorController.fontController.ensureInitialized.then(() => { + this.editorController.fontController.glyphsSearch = glyphsSearch; glyphsSearch.glyphMap = this.editorController.fontController.glyphMap; }); } From c58bba6b0bae7ebbf84fe376190b3d426ce67389 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Thu, 10 Oct 2024 14:47:43 +0200 Subject: [PATCH 3/4] Don't add glyphsSearch to fontController --- src/fontra/views/editor/editor.js | 2 +- src/fontra/views/editor/panel-glyph-search.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fontra/views/editor/editor.js b/src/fontra/views/editor/editor.js index 79462ad5b..fc670f3d0 100644 --- a/src/fontra/views/editor/editor.js +++ b/src/fontra/views/editor/editor.js @@ -2831,7 +2831,7 @@ export class EditorController { } async doSelectPreviousNextGlyph(selectPrevious) { - const filteredGlyphItems = this.fontController.glyphsSearch.filteredGlyphItems; + const filteredGlyphItems = this.glyphsSearch.filteredGlyphItems; const glyphNames = filteredGlyphItems.map((x) => x.glyphName); const selectedGlyphName = this.sceneSettings.selectedGlyphName; diff --git a/src/fontra/views/editor/panel-glyph-search.js b/src/fontra/views/editor/panel-glyph-search.js index 8503e4b39..e02a79099 100644 --- a/src/fontra/views/editor/panel-glyph-search.js +++ b/src/fontra/views/editor/panel-glyph-search.js @@ -19,6 +19,7 @@ export default class GlyphSearchPanel extends Panel { constructor(editorController) { super(editorController); const glyphsSearch = this.contentElement.querySelector("#glyphs-search"); + editorController.glyphsSearch = glyphsSearch; glyphsSearch.addEventListener("selectedGlyphNameChanged", (event) => this.glyphNameChangedCallback(event.detail) ); @@ -26,7 +27,6 @@ export default class GlyphSearchPanel extends Panel { glyphsSearch.updateGlyphNamesListContent(); }); this.editorController.fontController.ensureInitialized.then(() => { - this.editorController.fontController.glyphsSearch = glyphsSearch; glyphsSearch.glyphMap = this.editorController.fontController.glyphMap; }); } From 18cbc0f40d828c3e1fe5620a96c7ff851e398451 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Thu, 10 Oct 2024 17:15:37 +0200 Subject: [PATCH 4/4] Use "glyph-search" panel instead of adding glyphsSearch to editorController --- src/fontra/views/editor/editor.js | 3 ++- src/fontra/views/editor/panel-glyph-search.js | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fontra/views/editor/editor.js b/src/fontra/views/editor/editor.js index fc670f3d0..26635807c 100644 --- a/src/fontra/views/editor/editor.js +++ b/src/fontra/views/editor/editor.js @@ -2831,7 +2831,8 @@ export class EditorController { } async doSelectPreviousNextGlyph(selectPrevious) { - const filteredGlyphItems = this.glyphsSearch.filteredGlyphItems; + const panel = this.getSidebarPanel("glyph-search"); + const filteredGlyphItems = panel.glyphsSearch.filteredGlyphItems; const glyphNames = filteredGlyphItems.map((x) => x.glyphName); const selectedGlyphName = this.sceneSettings.selectedGlyphName; diff --git a/src/fontra/views/editor/panel-glyph-search.js b/src/fontra/views/editor/panel-glyph-search.js index e02a79099..27dd13062 100644 --- a/src/fontra/views/editor/panel-glyph-search.js +++ b/src/fontra/views/editor/panel-glyph-search.js @@ -18,16 +18,15 @@ export default class GlyphSearchPanel extends Panel { constructor(editorController) { super(editorController); - const glyphsSearch = this.contentElement.querySelector("#glyphs-search"); - editorController.glyphsSearch = glyphsSearch; - glyphsSearch.addEventListener("selectedGlyphNameChanged", (event) => + this.glyphsSearch = this.contentElement.querySelector("#glyphs-search"); + this.glyphsSearch.addEventListener("selectedGlyphNameChanged", (event) => this.glyphNameChangedCallback(event.detail) ); this.editorController.fontController.addChangeListener({ glyphMap: null }, () => { - glyphsSearch.updateGlyphNamesListContent(); + this.glyphsSearch.updateGlyphNamesListContent(); }); this.editorController.fontController.ensureInitialized.then(() => { - glyphsSearch.glyphMap = this.editorController.fontController.glyphMap; + this.glyphsSearch.glyphMap = this.editorController.fontController.glyphMap; }); }