fix: replace incomplete setting with a simpler one to show number of match results in notification

This commit is contained in:
rivea0 2025-04-13 00:16:30 +03:00
parent 70e04d5f75
commit 1e65237652
2 changed files with 10 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import { App, MarkdownView, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { App, MarkdownView, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { EditorView, ViewPlugin, Decoration } from '@codemirror/view';
import { MatchTextModal } from './modal';
import { getMatchRanges } from './utils';
@ -6,7 +6,7 @@ import type { PluginValue, DecorationSet, PluginSpec } from '@codemirror/view';
import type { MatchSyntaxPluginSettings, IRange } from './types';
const DEFAULT_SETTINGS: MatchSyntaxPluginSettings = {
showHighlightsOnReadingView: false,
showNumberOfMatchesNotification: false,
};
export default class MatchSyntaxPlugin extends Plugin {
@ -15,7 +15,6 @@ export default class MatchSyntaxPlugin extends Plugin {
async onload() {
await this.loadSettings();
this.addSettingTab(new MatchSyntaxSettingTab(this.app, this));
console.log(this.settings.showHighlightsOnReadingView);
const highlightViewPlugin = ViewPlugin.fromClass(
HighlighterPlugin,
@ -41,6 +40,9 @@ export default class MatchSyntaxPlugin extends Plugin {
if (plugin) {
plugin.makeDeco(ranges);
}
if (this.settings.showNumberOfMatchesNotification) {
new Notice(`${ranges.length} matches found.`);
}
}).open();
}
return true;
@ -97,13 +99,13 @@ class MatchSyntaxSettingTab extends PluginSettingTab {
containerEl.empty();
new Setting(containerEl)
.setName('Show highlights on reading view')
.setDesc('The match results will show both in editing and reading views')
.setName('Notify the number of matches found')
.setDesc('The number of match results will be shown in a notification when you search for a match syntax')
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.showHighlightsOnReadingView)
.setValue(this.plugin.settings.showNumberOfMatchesNotification)
.onChange(async (value) => {
this.plugin.settings.showHighlightsOnReadingView = value;
this.plugin.settings.showNumberOfMatchesNotification = value;
await this.plugin.saveSettings();
});
});

View file

@ -1,5 +1,5 @@
export interface MatchSyntaxPluginSettings {
showHighlightsOnReadingView: boolean;
showNumberOfMatchesNotification: boolean;
}
export interface IOffsetOutput {