mirror of
https://github.com/kunalja/VariantEditor.git
synced 2026-07-22 13:00:32 +00:00
clear dimming after modal close
This commit is contained in:
parent
c8f245ca35
commit
28aaeef501
2 changed files with 15 additions and 7 deletions
14
src/main.ts
14
src/main.ts
|
|
@ -464,21 +464,25 @@ export default class VariantEditor extends Plugin {
|
|||
new TextInputModal(
|
||||
this.app,
|
||||
initialText,
|
||||
(variantText, activeIndex, commitVariant, currentFrom, currentTo) => {
|
||||
(variantText, activeIndex, commitVariant, currentFrom, currentTo, modalClosed) => {
|
||||
// Use the updated cursor positions if provided, otherwise use the original positions
|
||||
const updateFrom = currentFrom || from;
|
||||
const updateTo = currentTo || to;
|
||||
|
||||
if (commitVariant) {
|
||||
// Replace the variant with just the active variant text
|
||||
if (modalClosed) {
|
||||
// Modal was closed without committing (via ESC key or clicking outside)
|
||||
// Clear the highlights
|
||||
this.clearHighlight();
|
||||
} else if (commitVariant === true) {
|
||||
// Replace the variant with just the active variant text (commit action)
|
||||
if (variantText) {
|
||||
editor.replaceRange(variantText, updateFrom, updateTo);
|
||||
new Notice(`Committed variant: "${variantText}"`);
|
||||
// Only clear highlights when committing
|
||||
// Clear highlights when committing
|
||||
this.clearHighlight();
|
||||
}
|
||||
} else {
|
||||
// Create or update the variant syntax
|
||||
// Create or update the variant syntax (normal variant creation/update)
|
||||
const variants = variantText.split('|').filter(v => v);
|
||||
|
||||
if (variants.length > 0) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export class TextInputModal extends Modal {
|
|||
private variants: string[] = [];
|
||||
private activeVariantIndex: number = 0;
|
||||
private lastNonEmptyVariantIndex: number = 0; // Track the last non-empty variant index
|
||||
private onSubmit: (result: string, activeIndex?: number, commitVariant?: boolean, currentFrom?: EditorPosition | null, currentTo?: EditorPosition | null) => void;
|
||||
private onSubmit: (result: string, activeIndex?: number, commitVariant?: boolean, currentFrom?: EditorPosition | null, currentTo?: EditorPosition | null, modalClosed?: boolean) => void;
|
||||
private originalText: string;
|
||||
private variantContainer: HTMLElement;
|
||||
private cursorPosition: EditorPosition | null;
|
||||
|
|
@ -19,7 +19,7 @@ export class TextInputModal extends Modal {
|
|||
constructor(
|
||||
app: App,
|
||||
originalText: string,
|
||||
onSubmit: (result: string, activeIndex?: number, commitVariant?: boolean, currentFrom?: EditorPosition | null, currentTo?: EditorPosition | null) => void,
|
||||
onSubmit: (result: string, activeIndex?: number, commitVariant?: boolean, currentFrom?: EditorPosition | null, currentTo?: EditorPosition | null, modalClosed?: boolean) => void,
|
||||
cursorPosition: EditorPosition | null = null,
|
||||
initialActiveIndex: number = 0,
|
||||
currentFrom: EditorPosition | null = null,
|
||||
|
|
@ -535,5 +535,9 @@ export class TextInputModal extends Modal {
|
|||
onClose() {
|
||||
const {contentEl} = this;
|
||||
contentEl.empty();
|
||||
|
||||
// Notify the parent that the modal was closed without committing
|
||||
// We pass an explicit modalClosed=true flag to indicate this was triggered by modal closing
|
||||
this.onSubmit(this.variants[this.activeVariantIndex], this.activeVariantIndex, false, this.currentFrom, this.currentTo, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue