Skip to content

Commit

Permalink
🚸 Add schema name to status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Apr 18, 2024
1 parent 0f55e32 commit 026a756
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ export async function activate(context: ExtensionContext): Promise<void> {

rime = new Rime(await userConfig.traits);
rime.setCompletionStatus(userConfig.enabled);
const statusBarItem = window.createStatusBarItem(0, { progress: false });
rime.getSchema().then((schemaId) => {
if (schemaId !== userConfig.schemaId && userConfig.schemaId !== '') rime.setSchema(userConfig.schemaId);
if (schemaId !== userConfig.schemaId && userConfig.schemaId !== '') {
rime.setSchema(userConfig.schemaId);
schemaId = userConfig.schemaId;
}
rime.getSchemaList().then((schemaList) => {
statusBarItem.text =
userConfig.shortcut +
' ' +
schemaList.filter((schema) => {
return schema.schema_id === schemaId;
})[0].name;
});
});
const statusBarItem = window.createStatusBarItem(0, { progress: false });
statusBarItem.text = userConfig.shortcut;
if (userConfig.enabled) {
statusBarItem.show();
}
Expand Down Expand Up @@ -163,7 +173,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
);

// Schema List
listManager.registerList(new SchemaList(workspace.nvim, rime));
listManager.registerList(new SchemaList(workspace.nvim, rime, statusBarItem, userConfig.shortcut));
}

export async function deactivate(): Promise<void> {
Expand Down
16 changes: 14 additions & 2 deletions src/lists.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasicList, ListAction, ListContext, ListItem, Neovim, window } from 'coc.nvim';
import { BasicList, ListAction, ListContext, ListItem, Neovim, window, StatusBarItem } from 'coc.nvim';
import { RimeSchema, Rime } from './rime';

export default class SchemaList extends BasicList {
Expand All @@ -10,10 +10,11 @@ export default class SchemaList extends BasicList {

private rime: Rime;

constructor(nvim: Neovim, rime: Rime) {
constructor(nvim: Neovim, rime: Rime, statusBarItem: StatusBarItem, shortcut: string) {
super(nvim);
this.rime = rime;
this.addAction('open', (item: ListItem) => {
let schemaId: string;
this.rime
.setSchema(item.data.schema_id)
.then((_) => {})
Expand All @@ -24,12 +25,23 @@ export default class SchemaList extends BasicList {
this.rime
.getSchema()
.then((schema_id) => {
schemaId = schema_id;
window.showMessage(`Changed to schema ${schema_id}.`);
})
.catch((e) => {
console.log(`Error get current schema: ${e}`);
window.showMessage(`Get current schema failed.`);
});
this.rime.getSchemaList().then((schema_list) => {
if (schemaId !== undefined) {
statusBarItem.text =
shortcut +
' ' +
schema_list.filter((schema) => {
return schema.schema_id === schemaId;
})[0].name;
}
});
});
}

Expand Down

0 comments on commit 026a756

Please sign in to comment.