Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select next/previous glyph #1706

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/fontra/client/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/fontra/client/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 导航",
Expand Down
1 change: 1 addition & 0 deletions src/fontra/client/web-components/glyphs-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class GlyphsSearch extends UnlitElement {
const filteredGlyphItems = this.glyphsListItems.filter(
this._glyphNamesListFilterFunc
);
this.filteredGlyphItems = filteredGlyphItems;
this.glyphNamesList.setItems(filteredGlyphItems);
}
}
Expand Down
49 changes: 49 additions & 0 deletions src/fontra/views/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -2804,6 +2830,29 @@ export class EditorController {
this.sceneSettings.selectedSourceIndex = newSourceIndex;
}

async doSelectPreviousNextGlyph(selectPrevious) {
const panel = this.getSidebarPanel("glyph-search");
const filteredGlyphItems = panel.glyphsSearch.filteredGlyphItems;
const glyphNames = filteredGlyphItems.map((x) => x.glyphName);

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;

Expand Down
8 changes: 4 additions & 4 deletions src/fontra/views/editor/panel-glyph-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export default class GlyphSearchPanel extends Panel {

constructor(editorController) {
super(editorController);
const glyphsSearch = this.contentElement.querySelector("#glyphs-search");
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;
});
}

Expand Down