mirror of
https://github.com/c-degni/text-autocomplete.git
synced 2026-07-22 05:49:39 +00:00
file structure and bug fixes
This commit is contained in:
parent
98807dd56d
commit
230d9b025d
11 changed files with 32 additions and 70 deletions
|
|
@ -23,7 +23,6 @@ The custom dictionary is a list of words you curate that is added to the plugin'
|
|||
- Words can be individually removed from the custom dictionary only from within the plugin settings
|
||||
- The custom dictionary can be reset in the plugin settings as well
|
||||
|
||||
|
||||
## Additional
|
||||
|
||||
- The maximum number of suggestions is modifiable in the plugin settings (3-10)
|
||||
|
|
@ -31,4 +30,4 @@ The custom dictionary is a list of words you curate that is added to the plugin'
|
|||
- English is the only supported language at the moment
|
||||
- For the time being, all features are disabled within code blocks (typing within code blocks is not supported)
|
||||
|
||||
#### Thank you to everyone using the plugin!
|
||||
#### Thanks to everyone using the plugin!
|
||||
|
|
@ -1,53 +1,3 @@
|
|||
// import { defineConfig, globalIgnores } from "eslint/config";
|
||||
// import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
||||
// import globals from "globals";
|
||||
// import tsParser from "@typescript-eslint/parser";
|
||||
// import path from "node:path";
|
||||
// import { fileURLToPath } from "node:url";
|
||||
// import js from "@eslint/js";
|
||||
// import { FlatCompat } from "@eslint/eslintrc";
|
||||
|
||||
// const __filename = fileURLToPath(import.meta.url);
|
||||
// const __dirname = path.dirname(__filename);
|
||||
// const compat = new FlatCompat({
|
||||
// baseDirectory: __dirname,
|
||||
// recommendedConfig: js.configs.recommended,
|
||||
// allConfig: js.configs.all
|
||||
// });
|
||||
|
||||
// export default defineConfig([globalIgnores(["**/node_modules/", "**/main.js"]), {
|
||||
// extends: compat.extends(
|
||||
// "eslint:recommended",
|
||||
// "plugin:@typescript-eslint/eslint-recommended",
|
||||
// "plugin:@typescript-eslint/recommended",
|
||||
// ),
|
||||
|
||||
// plugins: {
|
||||
// "@typescript-eslint": typescriptEslint,
|
||||
// },
|
||||
|
||||
// languageOptions: {
|
||||
// globals: {
|
||||
// ...globals.node,
|
||||
// },
|
||||
|
||||
// parser: tsParser,
|
||||
// ecmaVersion: 5,
|
||||
// sourceType: "module",
|
||||
// },
|
||||
|
||||
// rules: {
|
||||
// "no-unused-vars": "off",
|
||||
|
||||
// "@typescript-eslint/no-unused-vars": ["error", {
|
||||
// args: "none",
|
||||
// }],
|
||||
|
||||
// "@typescript-eslint/ban-ts-comment": "off",
|
||||
// "no-prototype-builtins": "off",
|
||||
// "@typescript-eslint/no-empty-function": "off",
|
||||
// },
|
||||
// }]);
|
||||
import esbuild from "esbuild";
|
||||
import process from "process";
|
||||
import builtins from "builtin-modules";
|
||||
|
|
@ -65,7 +15,7 @@ const context = await esbuild.context({
|
|||
banner: {
|
||||
js: banner,
|
||||
},
|
||||
entryPoints: ["main.ts"],
|
||||
entryPoints: ["src/main.ts"],
|
||||
bundle: true,
|
||||
external: [
|
||||
"obsidian",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
"minAppVersion": "1.8.10",
|
||||
"description": "Autocomplete text to type more efficiently.",
|
||||
"author": "Christ Degni",
|
||||
"isDesktopOnly": true,
|
||||
"css": "styles.css",
|
||||
"fundingUrl": "https://buymeacoffee.com/c.degni"
|
||||
"authorUrl": "https://github.com/c-degni",
|
||||
"fundingUrl": "https://buymeacoffee.com/c.degni",
|
||||
"isDesktopOnly": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "text-autocomplete",
|
||||
"version": "1.0.0",
|
||||
"description": "This is a text autocomplete plugin for Obsidian.",
|
||||
"description": "Autocomplete text to type more efficiently.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { Editor, EditorPosition, MarkdownView, Plugin, Menu, Notice } from 'obsidian';
|
||||
import { TASettingsTab, DEFAULT_SETTINGS, TASettings } from './settings';
|
||||
import { createTAUI, destroyTAUI, updateSuggestions } from './ui';
|
||||
import { DEFAULT_TRIE } from './dictionary';
|
||||
import { Trie } from './trie';
|
||||
import { TASettingsTab, DEFAULT_SETTINGS, TASettings } from './settings/settings';
|
||||
import { createTAUI, destroyTAUI, updateSuggestions } from './settings/ui';
|
||||
import { DEFAULT_TRIE } from './dictionary/dictionary';
|
||||
import { Trie } from './dictionary/trie';
|
||||
|
||||
// Helper functions
|
||||
function inCodeBlock(editor: Editor, cursor: EditorPosition): boolean {
|
||||
|
|
@ -128,7 +128,7 @@ export default class TAPlugin extends Plugin {
|
|||
}
|
||||
|
||||
// Handles plugin interaction from the context menu
|
||||
handleContextMenu(menu: Menu, editor: Editor, view: MarkdownView) {
|
||||
handleContextMenu(menu: Menu, editor: Editor) {
|
||||
const selectedText = editor.getSelection()?.trim();
|
||||
if (selectedText && /^.*$/.test(selectedText)) {
|
||||
menu.addItem(item =>
|
||||
|
|
@ -171,7 +171,7 @@ export default class TAPlugin extends Plugin {
|
|||
|
||||
if (evt.key === 'Enter' || evt.key === 'Tab') {
|
||||
const selected = active || items[0]; // Defaults to first suggestion
|
||||
if (selected) selected.dispatchEvent(new Event('click'));
|
||||
if (selected) selected.dispatchEvent(new Event('mousedown'));
|
||||
destroyTAUI();
|
||||
return;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { PluginSettingTab, App, Setting, Notice } from 'obsidian';
|
||||
import type TAPlugin from './main'
|
||||
import type TAPlugin from 'src/main';
|
||||
|
||||
// TODO Add LaTex support
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ export class TASettingsTab extends PluginSettingTab {
|
|||
}, 1000);
|
||||
});
|
||||
|
||||
this.plugin.settings.customDict.forEach((word, index) => {
|
||||
this.plugin.settings.customDict.forEach((word: string, index: number) => {
|
||||
const row = new Setting(scrollContainer)
|
||||
.setDesc(word)
|
||||
.addButton(b =>
|
||||
|
|
@ -123,7 +123,7 @@ export class TASettingsTab extends PluginSettingTab {
|
|||
b.setButtonText('Reset')
|
||||
.setCta()
|
||||
.onClick(async () => {
|
||||
this.plugin.settings.customDict.forEach(word => this.plugin.wordTrie.remove(word));
|
||||
this.plugin.settings.customDict.forEach((word: string) => this.plugin.wordTrie.remove(word));
|
||||
this.plugin.settings.customDict = [];
|
||||
await this.plugin.saveSettings();
|
||||
// new Notice('Custom dictionary cleared.')
|
||||
|
|
@ -7,6 +7,7 @@ export function createTAUI() {
|
|||
return [
|
||||
ViewPlugin.fromClass(
|
||||
class implements PluginValue {
|
||||
lastCursor: number | null;
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (!update.selectionSet && !update.docChanged && !update.focusChanged) return;
|
||||
|
|
@ -22,6 +23,7 @@ export function createTAUI() {
|
|||
// Destroy dropdown if cursor is in a word or before punctation
|
||||
if (/^[\w.,;:!?'"()\[\]{}\-_+=<>@#$%^&*]/.test(afterCursor)) {
|
||||
destroyTAUI();
|
||||
this.lastCursor = cursor;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -29,13 +31,21 @@ export function createTAUI() {
|
|||
// No matches (word at the end of the string)
|
||||
if (!match) {
|
||||
destroyTAUI();
|
||||
|
||||
this.lastCursor = cursor;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.lastCursor) return;
|
||||
const typing: boolean = this.lastCursor === cursor + 1 || this.lastCursor === cursor - 1;
|
||||
|
||||
if (!typing) {
|
||||
destroyTAUI();
|
||||
}
|
||||
this.lastCursor = cursor;
|
||||
}
|
||||
}
|
||||
)
|
||||
];
|
||||
// return [];
|
||||
}
|
||||
|
||||
export function destroyTAUI() {
|
||||
|
|
@ -57,7 +67,7 @@ export function updateSuggestions(suggestions: string[], editor: Editor, baseWor
|
|||
suggestions.forEach(suggestion => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = suggestion;
|
||||
li.onclick = () => {
|
||||
li.addEventListener('mousedown', () => {
|
||||
const cursor = editor.getCursor();
|
||||
const line = editor.getLine(cursor.line);
|
||||
const beforeCursor = line.substring(0, cursor.ch);
|
||||
|
|
@ -70,7 +80,7 @@ export function updateSuggestions(suggestions: string[], editor: Editor, baseWor
|
|||
);
|
||||
}
|
||||
destroyTAUI();
|
||||
};
|
||||
});
|
||||
dropdownEl?.appendChild(li);
|
||||
});
|
||||
|
||||
|
|
@ -11,6 +11,9 @@
|
|||
"importHelpers": true,
|
||||
"isolatedModules": true,
|
||||
"strictNullChecks": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"lib": [
|
||||
"DOM",
|
||||
"ES5",
|
||||
|
|
|
|||
Loading…
Reference in a new issue