mirror of
https://github.com/jglev/obsidian-apply-patterns-plugin.git
synced 2026-07-22 05:40:26 +00:00
Added ability to filter and rearrange Patterns.
This commit is contained in:
parent
800f4ee9b1
commit
50c8aea34c
6 changed files with 92 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "obsidian-apply-patterns",
|
||||
"name": "Apply Patterns",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"minAppVersion": "0.12.10",
|
||||
"description": "Apply custom patterns of find-and-replace in succession to text.",
|
||||
"author": "Jacob Levernier",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "obsidian-apply-patterns",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "An Obsidian plugin for applying patterns of find and replace in succession.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import cloneDeep from 'lodash.clonedeep';
|
|||
|
||||
export interface Settings {
|
||||
patterns: Pattern[];
|
||||
filterString?: string;
|
||||
}
|
||||
|
||||
export interface Pattern {
|
||||
|
|
@ -22,6 +23,7 @@ export interface PatternRule {
|
|||
|
||||
export const defaultSettings: Settings = {
|
||||
patterns: [],
|
||||
filterString: '',
|
||||
};
|
||||
|
||||
let settings: Settings = { ...defaultSettings };
|
||||
|
|
|
|||
|
|
@ -116,8 +116,49 @@ export class SettingsTab extends PluginSettingTab {
|
|||
cls: 'setting-item-description',
|
||||
});
|
||||
|
||||
new Setting(patternsEl)
|
||||
.addText((text) => {
|
||||
const settings = getSettings();
|
||||
text.setValue(settings.filterString || '').onChange(
|
||||
async (value) => {
|
||||
updateSettings({
|
||||
...cloneDeep(getSettings()),
|
||||
filterString: value,
|
||||
});
|
||||
|
||||
await this.plugin.saveSettings();
|
||||
},
|
||||
);
|
||||
}).addButton((button) => {
|
||||
button
|
||||
.setIcon(
|
||||
'magnifying-glass',
|
||||
)
|
||||
.setTooltip(
|
||||
'Filter Patterns',
|
||||
)
|
||||
.onClick(async () => {
|
||||
this.display();
|
||||
})})
|
||||
.setDesc('Filter patterns by name');
|
||||
|
||||
const patterns = getSettings().patterns;
|
||||
patterns.forEach((pattern: Pattern, patternIndex: number) => {
|
||||
for (const [patternIndex, pattern] of patterns.entries()) {
|
||||
const settings = getSettings();
|
||||
const patternFilterString = settings.filterString;
|
||||
if (
|
||||
patternFilterString !== undefined &&
|
||||
patternFilterString !== ''
|
||||
) {
|
||||
if (
|
||||
|
||||
!pattern.name.toLowerCase()
|
||||
.includes(patternFilterString.toLowerCase())
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const patternEl = patternsEl.createEl('div');
|
||||
patternEl.addClass('pattern');
|
||||
|
||||
|
|
@ -144,7 +185,50 @@ export class SettingsTab extends PluginSettingTab {
|
|||
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
})
|
||||
}).addExtraButton((button) => {
|
||||
button
|
||||
.setIcon('moveRowUp')
|
||||
.setTooltip('Move Pattern up')
|
||||
.setDisabled(patternIndex === 0)
|
||||
.onClick(async () => {
|
||||
let newPatterns = cloneDeep(
|
||||
getSettings().patterns,
|
||||
);
|
||||
newPatterns = moveInArray(
|
||||
newPatterns,
|
||||
patternIndex,
|
||||
patternIndex - 1,
|
||||
);
|
||||
updateSettings({
|
||||
patterns: newPatterns,
|
||||
});
|
||||
|
||||
await this.plugin.saveSettings();
|
||||
this.display();
|
||||
});
|
||||
})
|
||||
.addExtraButton((button) => {
|
||||
button
|
||||
.setIcon('moveRowDown')
|
||||
.setTooltip('Move Rule down')
|
||||
.setDisabled(patternIndex === patterns.length - 1)
|
||||
.onClick(async () => {
|
||||
let newPatterns = cloneDeep(
|
||||
getSettings().patterns,
|
||||
);
|
||||
newPatterns = moveInArray(
|
||||
newPatterns,
|
||||
patternIndex,
|
||||
patternIndex + 1,
|
||||
);
|
||||
updateSettings({
|
||||
patterns: newPatterns,
|
||||
});
|
||||
|
||||
await this.plugin.saveSettings();
|
||||
this.display();
|
||||
});
|
||||
})
|
||||
.addExtraButton((button) => {
|
||||
button
|
||||
.setIcon('cross')
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
}
|
||||
|
||||
.patterns .rule.disabled,
|
||||
.patterns .pattern .is-disabled,
|
||||
.patterns .rule .is-disabled {
|
||||
opacity: 50%;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
{
|
||||
"1.1.0": "0.12.10",
|
||||
"1.0.0": "0.12.10"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue