From e1940175ee5d96000a63007a9e7878cad2b9b6c1 Mon Sep 17 00:00:00 2001 From: Falcion <57592842+Falcion@users.noreply.github.com> Date: Sun, 31 May 2026 00:34:06 +0300 Subject: [PATCH 1/6] chore(release): start to fix issues with #171 and etc. by rewriting views --- source/components/views/interface_view.ts | 6 + source/components/views/view_code.ts | 117 +++++++++++++++++++ source/components/views/view_source.ts | 0 source/main.ts | 21 ++-- source/types/components/status/bar_config.ts | 8 ++ source/types/components/views/editor.ts | 5 + tsconfig.json | 7 +- 7 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 source/components/views/interface_view.ts create mode 100644 source/components/views/view_code.ts create mode 100644 source/components/views/view_source.ts create mode 100644 source/types/components/status/bar_config.ts create mode 100644 source/types/components/views/editor.ts diff --git a/source/components/views/interface_view.ts b/source/components/views/interface_view.ts new file mode 100644 index 0000000..c5f1639 --- /dev/null +++ b/source/components/views/interface_view.ts @@ -0,0 +1,6 @@ +import { UnitadeViewEditor } from "@typings/components/views/editor"; + +export interface IUnitadeView { + editor: UnitadeViewEditor; + extension: string; +} diff --git a/source/components/views/view_code.ts b/source/components/views/view_code.ts new file mode 100644 index 0000000..a2c2f8c --- /dev/null +++ b/source/components/views/view_code.ts @@ -0,0 +1,117 @@ + +import UnitadePlugin from "@main"; + +import { + TextFileView, + WorkspaceLeaf, + TFile +} from "obsidian"; + +import { IUnitadeView } from "@views/interface_view"; +import IUnitadeStatusBarPayload from "@typings/components/status/bar_config"; + +import * as monaco from 'monaco-editor'; + +import { genEditorSettings } from "../../utils/utils"; + +export class UnitadeViewCode extends TextFileView implements IUnitadeView { + editor!: monaco.editor.IStandaloneCodeEditor + extension: string = ''; + + constructor(leaf: WorkspaceLeaf, private plugin: UnitadePlugin) { + super(leaf); + } + + async onOpen() { + await super.onOpen(); + } + + async onLoadFile(file: TFile) { + const context = genEditorSettings(this.plugin.settings, this.file?.extension ?? ""); + + this.plugin.updateStatusBarInfo(this.prepStatusBarInfo()); + + this.editor = monaco.editor.create(this.contentEl, context); + this.editor.onDidChangeModelContent(() => { + this.requestSave(); + }); + this.editor.onDidChangeCursorPosition(() => { + this.plugin.updateStatusBarInfo(this.prepStatusBarInfo()); + }); + + this.addKeyActions(); + this.addMouseActions(); + + await super.onLoadFile(file); + } + + async onUnloadFile(file: TFile) { + this.removeKeyActions(); + this.removeMouseActions(); + + await super.onUnloadFile(file); + + this.editor.dispose(); + } + + async onClose() { + this.removeKeyActions(); + this.removeMouseActions(); + + await super.onClose(); + this.editor.dispose(); + } + + //#region Interface callbacks + onResize() { + this.editor.layout(); + } + + getViewType(): string { + return 'codeview'; + } + + getContext(file?: TFile) { + return file?.path ?? this.file?.path; + } + + getViewData = (): string => { + return this.editor.getValue(); + } + + setViewData = (data: string, clear: boolean) => { + if (clear) { + this.editor.getModel()?.setValue(data); + } else { + this.editor.setValue(data); + } + } + + clear = () => { + this.editor.setValue(''); + } + //#endregion + + private prepStatusBarInfo(): IUnitadeStatusBarPayload { + return { + cursor_lines: + this.editor.getPosition()?.lineNumber, + cursor_columns: + this.editor.getPosition()?.column, + display: + this.editor.getModel()?.getLanguageId(), + processor: + this.editor.getModel()?.id + } + } + + private addKeyActions(): void { + } + private removeKeyActions(): void { + } + + private addMouseActions(): void { + } + private removeMouseActions(): void { + } +} diff --git a/source/components/views/view_source.ts b/source/components/views/view_source.ts new file mode 100644 index 0000000..e69de29 diff --git a/source/main.ts b/source/main.ts index 69b164c..c30dd22 100644 --- a/source/main.ts +++ b/source/main.ts @@ -37,7 +37,7 @@ import UNITADE_SETTINGS_TAB, { DEFAULT_SETTINGS, } from './settings'; -import UNITADE_VIEW from './components/views/view_codemirror'; +import UnitadeViewSource from './components/views/-----view_source'; import CodeMirror from './../lib/codemirror'; @@ -66,7 +66,7 @@ import { import { TFilesRename } from './components/modals/files-rename'; import CONSTANTS from './utils/constants'; import LocalesModule from './locales/core'; -import { UNITADE_VIEW_CODE } from './components/views/view_monaco'; +import { UnitadeViewCode } from './components/views/----view_code'; import { ContextEditor } from './components/contexts/contextEditor'; import { FenceEditModal } from './components/modals/codeblock-edit'; import { ContextEditCodeblocks } from './components/contextEditCodeblock'; @@ -76,6 +76,7 @@ import { PromptUserInput } from './components/modals/prompt-user-input'; import './_exportMonaco'; import { DEFAULT_SIGNATURES } from './externals/errors/signatures'; +import IUnitadeStatusBarPayload from '@typings/components/status/bar_config'; declare module "obsidian" { interface Workspace { @@ -100,7 +101,8 @@ export default class UNITADE_PLUGIN extends Plugin { private _observer!: MutationObserver; private _statusBar!: HTMLElement; - public statusBarConfig: StatusBarConfig = new StatusBarConfig(this._locale); + + public StatusBarInfo: StatusBarConfig = new StatusBarConfig(this._locale); public hover: { linkText: string; @@ -389,7 +391,7 @@ export default class UNITADE_PLUGIN extends Plugin { if (this.settings.debug_mode && this.settings.status_bar.cursor_position) console.debug('[UNITADE] CHECKED CURSOR POSITION OF EDITOR-CHANGE EVENT:', editor.getCursor()); - this.statusBarConfig.update({ + this.StatusBarInfo.update({ cursor_columns: editor.getCursor().ch, cursor_lines: editor.getCursor().line, }); @@ -449,7 +451,7 @@ export default class UNITADE_PLUGIN extends Plugin { if (this.settings.debug_mode && this.settings.status_bar.cursor_position) console.debug('[UNITADE] CHECKED CURSOR POSITION OF LEAF-CHANGE EVENT:', cursor); - this.statusBarConfig.update({ + this.StatusBarInfo.update({ cursor_columns: cursor.ch, cursor_lines: cursor.line, display: viewType, @@ -585,7 +587,7 @@ export default class UNITADE_PLUGIN extends Plugin { //#region Status bar update public updateStatusBar(): void { - if (this.settings.status_bar.enabled) { + if (this.settings.status_bar.enable) { const data: string[] = new StatusBarParser(this._locale, this.statusBarConfig).generateText(); let text: string = ''; @@ -779,7 +781,7 @@ export default class UNITADE_PLUGIN extends Plugin { if (this.app.viewRegistry.viewByType['codeview'] === undefined || this.app.viewRegistry.viewByType['codeview'] === null) - this.registerView('codeview', leaf => new UNITADE_VIEW_CODE(leaf, this)); + this.registerView('codeview', leaf => new UnitadeViewCode(leaf, this)); if (this.settings.is_grouped) { const data: { [key: string]: string[] } = parsegroup(this.settings.grouped_extensions); @@ -819,7 +821,7 @@ export default class UNITADE_PLUGIN extends Plugin { for (const extension of forced_extensions) { try { this.registerView(extension, (leaf: WorkspaceLeaf) => { - return new UNITADE_VIEW(leaf, extension); + return new UnitadeViewSource(leaf, extension); }); } catch (err: any) { this.settings.errors[extension] = `${this.locale.getLocaleItem('ERROR_COMMON_MESSAGE')[0]!} ${err}`; @@ -976,4 +978,7 @@ export default class UNITADE_PLUGIN extends Plugin { } } //#endregion + public updateStatusBarInfo(data: Partial): void { + //TODO: update status bar + } } diff --git a/source/types/components/status/bar_config.ts b/source/types/components/status/bar_config.ts new file mode 100644 index 0000000..77dc009 --- /dev/null +++ b/source/types/components/status/bar_config.ts @@ -0,0 +1,8 @@ +export default interface IUnitadeStatusBarPayload { + cursor_lines?: number; + cursor_columns?: number; + display?: string; + processor?: string; + registered_views?: number; + registered_extensions?: number; +} diff --git a/source/types/components/views/editor.ts b/source/types/components/views/editor.ts new file mode 100644 index 0000000..56044b9 --- /dev/null +++ b/source/types/components/views/editor.ts @@ -0,0 +1,5 @@ +import CodeMirror from '@codemirror/lib'; +import { editor } from 'monaco-editor'; + +export type UnitadeViewEditor = editor.IStandaloneCodeEditor | CodeMirror.Editor; + diff --git a/tsconfig.json b/tsconfig.json index e0134e7..040d9df 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,19 +7,20 @@ "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "skipLibCheck": true, - "downlevelIteration": true, "target": "ES2023", "lib": ["es2022", "dom", "dom.iterable"], "outDir": "out", - "baseUrl": "./", "incremental": true, - "moduleResolution": "node", "esModuleInterop": true, "strict": true, "sourceMap": false, "allowJs": true, "types": ["obsidian-typings", "monaco-editor", "./source/types/workers.d.ts"], "paths": { + "@main": ["./source/main"], + "@codemirror/lib": ["./lib/codemirror"], + "@typings/*": ["./source/types/*"], + "@views/*": ["./source/components/views/*"], "monaco-editor/esm/vs/*": ["./src/types/monaco-workers.d.ts"] } }, From 0977b35d963015676e5f97ddf19f15fee251b615 Mon Sep 17 00:00:00 2001 From: Falcion <57592842+Falcion@users.noreply.github.com> Date: Sun, 31 May 2026 00:34:16 +0300 Subject: [PATCH 2/6] chore(release): start to fix issues with #171 and etc. by rewriting views --- source/components/views/view_codemirror.ts | 90 ---------------------- 1 file changed, 90 deletions(-) delete mode 100644 source/components/views/view_codemirror.ts diff --git a/source/components/views/view_codemirror.ts b/source/components/views/view_codemirror.ts deleted file mode 100644 index 20f88be..0000000 --- a/source/components/views/view_codemirror.ts +++ /dev/null @@ -1,90 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023-2024 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Any code and/or API associated with OBSIDIAN behaves as stated in their distribution policy. - */ - -import { - TextFileView, - WorkspaceLeaf, -} from "obsidian"; - -import CodeMirror from '../../../lib/codemirror'; - -export default class UNITADE_VIEW extends TextFileView { - private _codemirror: CodeMirror.Editor; - - private _extension: string = ''; - - constructor(leaf: WorkspaceLeaf, extension: string) { - super(leaf); - - this._extension = extension; - - - this._codemirror = CodeMirror(this.contentEl, { - theme: 'obsidian', - }); - - this._codemirror.on('changes', this.onChange); - } - - onResize(): void { - this._codemirror.refresh(); - } - - onChange = async () => { - this.requestSave(); - } - - getViewData(): string { - return this._codemirror.getValue(); - } - - setViewData(data: string, clear: boolean): void { - if (clear) - this._codemirror.swapDoc(CodeMirror.Doc(data, `text/x-${this._extension}`)); - else - this._codemirror.setValue(data); - } - - clear(): void { - this._codemirror.setValue(''); - this._codemirror.clearHistory(); - } - - getDisplayText(): string { - if (this.file) - return this.file.basename; - else - return 'no file'; - } - - canAcceptExtension(extension: string): boolean { - return extension === this._extension; - } - - getViewType(): string { - return 'mirrorview'; - } -} From 0ace1cc3eb03a2a026fee042520a17e646303236 Mon Sep 17 00:00:00 2001 From: Falcion <57592842+Falcion@users.noreply.github.com> Date: Fri, 3 Jul 2026 18:47:25 +0300 Subject: [PATCH 3/6] build(build-env): define path, optimize package and it's build pipeline --- esbuild.config.mjs | 44 +++++++++----------------------------------- jsconfig.json | 24 +++++++++--------------- package.json | 33 +-------------------------------- tsconfig.json | 9 ++++----- 4 files changed, 23 insertions(+), 87 deletions(-) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 3116980..4a579b8 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -5,7 +5,6 @@ import process from "process"; import builtins from "builtin-modules"; import glsl from "esbuild-plugin-glsl"; import fs from 'fs'; -import path from 'node:path'; const banner = `/* @@ -37,46 +36,20 @@ let manifest = { } } -// const workerPlugin = { -// name: 'monaco-workers', -// setup(build) { -// build.onResolve({ filter: /\.worker\.js$/ }, async (args) => { -// return { -// path: path.resolve(args.resolveDir, args.path), -// namespace: 'monaco-worker', -// }; -// }); +import * as dotenv from 'dotenv' -// build.onLoad({ filter: /.*/, namespace: 'monaco-worker' }, async (args) => { -// // Bundle worker code into a self-contained script -// const result = await esbuild.build({ -// entryPoints: [args.path], -// bundle: true, -// format: 'iife', -// write: false, -// target: 'es6', -// }); - -// const code = result.outputFiles[0].text; -// return { -// contents: `export default ${JSON.stringify(code)};`, -// loader: 'js', -// }; -// }); -// } -// }; +dotenv.config(); let autotest = { name: 'autotest', setup(build) { build.onEnd(() => { - const PUT_YOUR_PATH_HERE_IF_ENABLED = ''; - const ENABLED = false; + const args = process.argv.splice(2); - if (ENABLED) { - fs.copyFileSync('out/manifest.json', PUT_YOUR_PATH_HERE_IF_ENABLED); - fs.copyFileSync('out/main.js', PUT_YOUR_PATH_HERE_IF_ENABLED); - fs.copyFileSync('out/styles.css', PUT_YOUR_PATH_HERE_IF_ENABLED); + if (args.includes('--autotest')) { + fs.copyFileSync('out/manifest.json', process.env.TESTING_PATH); + fs.copyFileSync('out/main.js', process.env.TESTING_PATH); + fs.copyFileSync('out/styles.css', process.env.TESTING_PATH); } }); } @@ -97,7 +70,6 @@ const context = await esbuild.context({ glsl({ minify: true, }), - // workerPlugin, { name: 'worker-plugin', setup(build) { @@ -132,6 +104,8 @@ const context = await esbuild.context({ "@lezer/common", "@lezer/highlight", "@lezer/lr", + "./mode", + "./lib", ...builtins], format: "cjs", target: "es6", diff --git a/jsconfig.json b/jsconfig.json index 7a7fc51..84c5df6 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,16 +1,10 @@ { - "compilerOptions": { - "module": "ESNext", - "moduleResolution": "Node", - "target": "ES2020", - "jsx": "react", - "strictNullChecks": true, - "strictFunctionTypes": true - }, - "exclude": [ - "env", - "**/env/*", - "node_modules", - "**/node_modules/*" - ] -} \ No newline at end of file + "compilerOptions": { + "module": "ESNext", + "target": "ES2020", + "jsx": "react", + "strictNullChecks": true, + "strictFunctionTypes": true + }, + "exclude": ["env", "**/env/*", "node_modules", "**/node_modules/*"] +} diff --git a/package.json b/package.json index d77d93d..25fc5ba 100644 --- a/package.json +++ b/package.json @@ -17,35 +17,6 @@ ], "readme": "https://github.com/Falcion/UNITADE.md#readme", "scripts": { - "lint": "node ./script/lint.js && npm run lint:docs", - "lint:js": "node ./script/lint.js --js", - "lint:clang-format": "python3 script/pytohn/run-clang-format.py -r -c shell/ || (echo \"\\nCode not formatted correctly.\" && exit 1)", - "lint:clang-tidy": "python3 ./script/python/run-clang-tidy.py", - "lint:cpp": "node ./script/lint.js --cc", - "lint:objc": "node ./script/lint.js --objc", - "lint:py": "node ./script/lint.js --py", - "lint:gn": "node ./script/lint.js --gn", - "lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run ct-typescript-definitions && npm run lint:ts-check-js-in-markdown && npm run lint:docs-fiddles && npm run lint:docs-relative-links && npm run lint:markdown", - "lint:docs-fiddles": "standard \"docs/fiddles/**/*.js\"", - "lint:docs-relative-links": "electron-lint-markdown-links --root docs \"**/*.md\"", - "lint:markdown": "node ./script/lint.js --md", - "lint:ts-check-js-in-markdown": "electron-lint-markdown-ts-check --root docs \"**/*.md\" --ignore \"breaking-changes.md\"", - "lint:js-in-markdown": "electron-lint-markdown-standard --root docs \"**/*.md\"", - "create-api-json": "node script/js/create-api-json.js", - "ct-typescript-definitions": "npm run create-api-json && electron-typescript-definitions", - "gn-typescript-definitions": "npm run ct-typescript-definitions && shx cp environment.d.ts", - "pre-flight": "pre-flight", - "gn-check": "node ./script/js/gn-check.js", - "gn-format": "python3 script/python/run-gn-format.py", - "preversion": "npm i --force", - "precommit": "lint-staged", - "preinstall": "node -e 'process.exit(0)'", - "pretest": "npm run ct-typescript-definitions", - "prepack": "check-for-leaks", - "prepare": "husky .husky/ && cd scripts/python && python3 -m venv venv", - "update-analytics": "ts-node scripts/js/analytics-workflow.ts", - "test": "node ./script/spec-runner.js", - "start": "tsc && node out/environment.js", "buildtsc": "tsc", "install": "npm run start", "pack": "python scripts/python/pack.py", @@ -53,10 +24,8 @@ "release:minor": "standard-version --release-as minor", "release:patch": "standard-version --release-as patch", "release:major": "standard-version --release-as major", - "generate-version-json": "node scripts/js/generate-version-json.js", - "cli": ".\\gh.cli.sh", "build": "tsc -noEmit && node esbuild.config.mjs production", - "build-nocheck": "tsc -noEmit -skipLibCheck --esModuleInterop --noCheck --downlevelIteration source/main.ts && node esbuild.config.mjs production" + "build:test": "tsc -noEmit && node esbuild.config.mjs production --autotest" }, "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json index e0134e7..4ad199c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,22 +7,21 @@ "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "skipLibCheck": true, - "downlevelIteration": true, "target": "ES2023", "lib": ["es2022", "dom", "dom.iterable"], "outDir": "out", - "baseUrl": "./", "incremental": true, - "moduleResolution": "node", "esModuleInterop": true, "strict": true, "sourceMap": false, "allowJs": true, "types": ["obsidian-typings", "monaco-editor", "./source/types/workers.d.ts"], "paths": { - "monaco-editor/esm/vs/*": ["./src/types/monaco-workers.d.ts"] + "monaco-editor/esm/vs/*": ["./src/types/workers.d.ts"], + "codemirror/mode/*": ["./mode/*"], + "codemirror/lib/*": ["./lib/*"] } }, "exclude": ["node_modules", "out", "git", "venv"], - "include": ["**/*.ts", "**/*.d.ts", "build/meta_url_transformer.js"] + "include": ["**/*.ts", "**/*.d.ts"] } From e46665455f11687bd48d3893f6f126ae5f111311 Mon Sep 17 00:00:00 2001 From: Falcion <57592842+Falcion@users.noreply.github.com> Date: Fri, 3 Jul 2026 18:47:59 +0300 Subject: [PATCH 4/6] refactor(mirrorview): little refactoring towards CodeMirror view --- source/components/views/view_codemirror.ts | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/source/components/views/view_codemirror.ts b/source/components/views/view_codemirror.ts index 20f88be..b12ba5a 100644 --- a/source/components/views/view_codemirror.ts +++ b/source/components/views/view_codemirror.ts @@ -32,25 +32,30 @@ import { import CodeMirror from '../../../lib/codemirror'; export default class UNITADE_VIEW extends TextFileView { - private _codemirror: CodeMirror.Editor; - + private _editor: CodeMirror.Editor; private _extension: string = ''; + public get editor(): CodeMirror.Editor { + return this._editor; + } + public get extension(): string { + return this._extension; + } + constructor(leaf: WorkspaceLeaf, extension: string) { super(leaf); this._extension = extension; - this._codemirror = CodeMirror(this.contentEl, { + this._editor = CodeMirror(this.contentEl, { theme: 'obsidian', }); - - this._codemirror.on('changes', this.onChange); + this._editor.on('changes', this.onChange); } onResize(): void { - this._codemirror.refresh(); + this._editor.refresh(); } onChange = async () => { @@ -58,19 +63,29 @@ export default class UNITADE_VIEW extends TextFileView { } getViewData(): string { - return this._codemirror.getValue(); + return this._editor.getValue(); } setViewData(data: string, clear: boolean): void { if (clear) - this._codemirror.swapDoc(CodeMirror.Doc(data, `text/x-${this._extension}`)); + this._editor.swapDoc(CodeMirror.Doc(data, `text/x-${this._extension}`)); else - this._codemirror.setValue(data); + this._editor.setValue(data); } clear(): void { - this._codemirror.setValue(''); - this._codemirror.clearHistory(); + this._editor.setValue(''); + this._editor.clearHistory(); + } + + async onOpen(): Promise { + super.onOpen(); + } + + async onClose(): Promise { + super.onClose(); + + this.clear(); } getDisplayText(): string { From fa72471a314de40d08043cf28bb6e467fab5e95d Mon Sep 17 00:00:00 2001 From: Falcion <57592842+Falcion@users.noreply.github.com> Date: Fri, 3 Jul 2026 18:48:44 +0300 Subject: [PATCH 5/6] refactor(codeview): systemize keypress-handling and reduce code smell --- source/components/views/view_monaco.ts | 84 ++++++++++++++++---------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/source/components/views/view_monaco.ts b/source/components/views/view_monaco.ts index 3c25af7..314c1e3 100644 --- a/source/components/views/view_monaco.ts +++ b/source/components/views/view_monaco.ts @@ -60,23 +60,19 @@ export class UNITADE_VIEW_CODE extends TextFileView { } async onUnloadFile(file: TFile) { - this.containerEl.removeEventListener('keydown', this.__keyHandler, true); - this.containerEl.removeEventListener('wheel', this.__mousewheelHandler); + this.containerEl.removeEventListener('keydown', this.keyboardHandler, true); + this.containerEl.removeEventListener('wheel', this.mouseWheelHandler); await super.onUnloadFile(file); - await this.__saveFontSize(); - this.monacoEditor.dispose(); } async onClose() { - this.containerEl.removeEventListener('keydown', this.__keyHandler, true); - this.containerEl.removeEventListener('wheel', this.__mousewheelHandler); + this.containerEl.removeEventListener('keydown', this.keyboardHandler, true); + this.containerEl.removeEventListener('wheel', this.mouseWheelHandler); await super.onClose(); - - await this.__saveFontSize(); } onResize() { @@ -113,46 +109,43 @@ export class UNITADE_VIEW_CODE extends TextFileView { } private addKeyEvents = () => { - this.containerEl.addEventListener('keydown', this.__keyHandler, true); + this.containerEl.addEventListener('keydown', this.keyboardHandler, true); // Bind custom paste handler to Ctrl+V (or Cmd+V on Mac) if (this.plugin.settings.code_editor_settings.force_vanilla_paste) { this.monacoEditor.addCommand( monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyV, - () => this.__handlePaste() + () => this.customHandlePaste() ); } // Bind custom paste handler to Shift+Insert this.monacoEditor.addCommand( monaco.KeyMod.Shift | monaco.KeyCode.Insert, - () => this.__handlePaste() + () => this.customHandlePaste() ); } private addCtrlKeyWheelEvents = () => { if (this.plugin.settings.code_editor_settings.enable_zoom) - this.containerEl.addEventListener('wheel', this.__mousewheelHandler, { + this.containerEl.addEventListener('wheel', this.mouseWheelHandler, { capture: this.plugin.settings.code_editor_settings.enable_zoom, passive: !this.plugin.settings.code_editor_settings.enable_zoom, }); } - private __handlePaste = async () => { + private customHandlePaste = async () => { try { this.monacoEditor.focus(); - // Get the current clipboard contents const text = await navigator.clipboard.readText(); - // Get the current selection in the editor const selection = this.monacoEditor.getSelection(); if (!selection) { return; } - // Replace the current selection with the text from the clipboard this.monacoEditor.executeEdits("clipboard", [{ range: selection, text: text, @@ -172,13 +165,19 @@ export class UNITADE_VIEW_CODE extends TextFileView { }); } catch (error) { console.error('Failed to paste from clipboard:', error); - // If clipboard API fails, let Monaco try its default behavior + + // If custom handle fails, try to call for standard API callback + navigator.clipboard.readText().then((clipboard) => { + this.monacoEditor.trigger('', 'paste', { text: clipboard }); + }) } } - private __keyHandler = async (event: KeyboardEvent) => { + private keyboardHandler = async (event: KeyboardEvent) => { if (this.getViewType() !== 'codeview') return; + const modEnabled = event.ctrlKey || event.metaKey; + const KEYMAP = new Map([ ['f', 'actions.find'], ['h', 'editor.action.startFindReplaceAction'], @@ -189,11 +188,40 @@ export class UNITADE_VIEW_CODE extends TextFileView { ['d', 'editor.action.copyLinesDownAction'], ]); - if (event.ctrlKey) { + if (modEnabled) { const trigger_name = KEYMAP.get(event.key); - if (trigger_name) - this.monacoEditor.trigger('', trigger_name, null); + if (trigger_name) { + event.preventDefault(); + event.stopPropagation(); + + // We don't need to use "Paste" trigger since we + // have {handlePaste} + + if (trigger_name === 'copy') { + const selection = this.monacoEditor.getSelection(); + const model = this.monacoEditor.getModel(); + + if (selection && model) + navigator.clipboard.writeText(model.getValueInRange(selection)); + + } + else if (trigger_name === 'cut') { + const selection = this.monacoEditor.getSelection(); + const model = this.monacoEditor.getModel(); + if (selection && model) { + navigator.clipboard.writeText(model.getValueInRange(selection)); + + this.monacoEditor.executeEdits('cut', [{ + range: selection, + text: '', + forceMoveMarkers: true + }]); + } + } + else + this.monacoEditor.trigger('', trigger_name, null); + } } if (event.altKey) { @@ -215,8 +243,10 @@ export class UNITADE_VIEW_CODE extends TextFileView { } } - private __mousewheelHandler = async (event: WheelEvent) => { - if (event.ctrlKey) { + private mouseWheelHandler = async (event: WheelEvent) => { + const modEnabled = event.ctrlKey || event.metaKey; + + if (modEnabled) { const delta = event.deltaY > 0 ? 1 : -1; this.monacoEditor!.updateOptions({ @@ -226,12 +256,4 @@ export class UNITADE_VIEW_CODE extends TextFileView { event.stopPropagation(); } } - - private __saveFontSize = async () => { - // await this.plugin.uptSettingsVisuals({ - // code_editor_settings: { - // ...this.plugin.settings.code_editor.visuals, - // font_size: this.monacoEditor.getOption(monaco.editor.EditorOption.fontSize) - // }); - } } From 8a08eb5afb1a7f00bc0ab47853281eabd407a19f Mon Sep 17 00:00:00 2001 From: Falcion <57592842+Falcion@users.noreply.github.com> Date: Fri, 3 Jul 2026 18:54:37 +0300 Subject: [PATCH 6/6] Revert changes from merge local -> origin --- source/components/views/view_monaco.ts | 4 ++-- source/main.ts | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/source/components/views/view_monaco.ts b/source/components/views/view_monaco.ts index 314c1e3..63e9869 100644 --- a/source/components/views/view_monaco.ts +++ b/source/components/views/view_monaco.ts @@ -35,7 +35,7 @@ export class UNITADE_VIEW_CODE extends TextFileView { this.addCtrlKeyWheelEvents(); this.addKeyEvents(); - this.plugin.statusBarConfig.update({ + this.plugin.StatusBarInfo.update({ cursor_columns: this.monacoEditor.getPosition() ? this.monacoEditor.getPosition()!.column : 0, cursor_lines: this.monacoEditor.getPosition() ? this.monacoEditor.getPosition()!.lineNumber : 0, processor: this.monacoEditor.getModel() ? this.monacoEditor.getModel()!.id : this.plugin.locale.getLocaleItem('STATUS_BAR')[0]!, @@ -48,7 +48,7 @@ export class UNITADE_VIEW_CODE extends TextFileView { const cursor = this.monacoEditor.getPosition(); if (cursor) - this.plugin.statusBarConfig.update({ + this.plugin.StatusBarInfo.update({ cursor_columns: cursor.column, cursor_lines: cursor.lineNumber }); diff --git a/source/main.ts b/source/main.ts index c30dd22..15248d6 100644 --- a/source/main.ts +++ b/source/main.ts @@ -37,8 +37,6 @@ import UNITADE_SETTINGS_TAB, { DEFAULT_SETTINGS, } from './settings'; -import UnitadeViewSource from './components/views/-----view_source'; - import CodeMirror from './../lib/codemirror'; import { @@ -66,7 +64,6 @@ import { import { TFilesRename } from './components/modals/files-rename'; import CONSTANTS from './utils/constants'; import LocalesModule from './locales/core'; -import { UnitadeViewCode } from './components/views/----view_code'; import { ContextEditor } from './components/contexts/contextEditor'; import { FenceEditModal } from './components/modals/codeblock-edit'; import { ContextEditCodeblocks } from './components/contextEditCodeblock'; @@ -76,7 +73,8 @@ import { PromptUserInput } from './components/modals/prompt-user-input'; import './_exportMonaco'; import { DEFAULT_SIGNATURES } from './externals/errors/signatures'; -import IUnitadeStatusBarPayload from '@typings/components/status/bar_config'; +import { UNITADE_VIEW_CODE } from './components/views/view_monaco'; +import UNITADE_VIEW from './components/views/view_codemirror'; declare module "obsidian" { interface Workspace { @@ -587,8 +585,8 @@ export default class UNITADE_PLUGIN extends Plugin { //#region Status bar update public updateStatusBar(): void { - if (this.settings.status_bar.enable) { - const data: string[] = new StatusBarParser(this._locale, this.statusBarConfig).generateText(); + if (this.settings.status_bar.enabled) { + const data: string[] = new StatusBarParser(this._locale, this.StatusBarInfo).generateText(); let text: string = ''; @@ -781,7 +779,7 @@ export default class UNITADE_PLUGIN extends Plugin { if (this.app.viewRegistry.viewByType['codeview'] === undefined || this.app.viewRegistry.viewByType['codeview'] === null) - this.registerView('codeview', leaf => new UnitadeViewCode(leaf, this)); + this.registerView('codeview', leaf => new UNITADE_VIEW_CODE(leaf, this)); if (this.settings.is_grouped) { const data: { [key: string]: string[] } = parsegroup(this.settings.grouped_extensions); @@ -821,7 +819,7 @@ export default class UNITADE_PLUGIN extends Plugin { for (const extension of forced_extensions) { try { this.registerView(extension, (leaf: WorkspaceLeaf) => { - return new UnitadeViewSource(leaf, extension); + return new UNITADE_VIEW(leaf, extension); }); } catch (err: any) { this.settings.errors[extension] = `${this.locale.getLocaleItem('ERROR_COMMON_MESSAGE')[0]!} ${err}`; @@ -978,7 +976,4 @@ export default class UNITADE_PLUGIN extends Plugin { } } //#endregion - public updateStatusBarInfo(data: Partial): void { - //TODO: update status bar - } }