Skip to content

Commit

Permalink
Make language selector also search through the languages' filename su…
Browse files Browse the repository at this point in the history
…ffixes (using the guesslang attribute)

This makes the "cpp" string match C++, and "cs" match C#.
  • Loading branch information
heyman committed Jan 3, 2025
1 parent ff88091 commit c87ea67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/LanguageSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
const items = LANGUAGES.map(l => {
return {
"token": l.token,
"name": l.name
"name": l.name,
"guesslang": l.guesslang,
}
}).sort((a, b) => {
return a.name.localeCompare(b.name)
Expand Down Expand Up @@ -35,12 +36,13 @@
return items
}
const searchResults = fuzzysort.go(this.filter, items, {
keys: ['name'],
keys: ['name', 'guesslang'],
})
return searchResults.map(result => {
const highlight = result[0].highlight("<b>", "</b>")
return {
"token": result.obj.token,
"name": result[0].highlight("<b>", "</b>")
"name": highlight || result.obj.name,
}
})
},
Expand Down
16 changes: 16 additions & 0 deletions tests/language-selector.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test, expect } from "@playwright/test";
import { HeynotePage } from "./test-utils.js";

let heynotePage

test.beforeEach(async ({ page }) => {
heynotePage = new HeynotePage(page)
await heynotePage.goto()
})


test("test language selector search by file ending", async ({ page }) => {
await page.locator("body").press(heynotePage.agnosticKey("Mod+L"))
await page.locator("body").pressSequentially("cpp")
await expect(page.locator("css=.language-selector .items > li.selected")).toHaveText("C++")
})

0 comments on commit c87ea67

Please sign in to comment.