This commit is contained in:
Oscar Plaisant
2024-04-01 17:56:28 +02:00
parent 7d8f480760
commit b2eb62ad98
67 changed files with 2874 additions and 6269 deletions

View File

@@ -16,7 +16,8 @@
"checkboxes",
"dataview",
"tabs_on_multiple_rown",
"compact_tabs"
"compact_tabs",
"popup_preview_size"
],
"interfaceFontFamily": "CMU Sans Serif,FiraCode Nerd Font",
"textFontFamily": "CMU Sans Serif,FiraCode Nerd Font",

View File

@@ -39,5 +39,9 @@
"obsidian-zoom",
"zotlit",
"obsidian-style-settings",
"obsidian-hider"
"obsidian-hider",
"inline-math",
"quick-preview",
"obsidian42-brat",
"obsidian-vault-statistics-plugin"
]

10
.obsidian/graph.json vendored
View File

@@ -120,16 +120,16 @@
}
}
],
"collapse-display": true,
"collapse-display": false,
"showArrow": false,
"textFadeMultiplier": 0,
"nodeSizeMultiplier": 1.33716227213542,
"lineSizeMultiplier": 1.19619954427083,
"nodeSizeMultiplier": 0.827272727272727,
"lineSizeMultiplier": 1.108,
"collapse-forces": true,
"centerStrength": 0.1812744140625,
"repelStrength": 6.39485677083333,
"linkStrength": 1,
"linkDistance": 30,
"scale": 0.07115186299616377,
"close": true
"scale": 0.05607792726105202,
"close": false
}

View File

@@ -0,0 +1,5 @@
{
"disableInTable": false,
"disableDecorations": false,
"disableAtomicRanges": false
}

451
.obsidian/plugins/inline-math/main.js vendored Normal file
View File

@@ -0,0 +1,451 @@
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/main.ts
var main_exports = {};
__export(main_exports, {
default: () => NoMoreFlicker
});
module.exports = __toCommonJS(main_exports);
var import_obsidian2 = require("obsidian");
// src/settings.ts
var import_obsidian = require("obsidian");
var DEFAULT_SETTINGS = {
disableInTable: false,
disableDecorations: false,
disableAtomicRanges: false
};
var NoMoreFlickerSettingTab = class extends import_obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
new import_obsidian.Setting(containerEl).setName("Disable in tables").setDesc("If turned on, braces won't be inserted in tables. Decorations & atomic ranges are enabled regardless of this setting.").addToggle((toggle) => {
toggle.setValue(this.plugin.settings.disableInTable).onChange(async (disable) => {
this.plugin.settings.disableInTable = disable;
await this.plugin.saveSettings();
});
});
containerEl.createEl("h4", { text: "Debug mode" });
new import_obsidian.Setting(containerEl).setName("Disable decorations").setDesc("If turned on, decorations to hide braces adjacent to dollar signs are disabled.").addToggle((toggle) => {
toggle.setValue(this.plugin.settings.disableDecorations).onChange(async (disable) => {
this.plugin.settings.disableDecorations = disable;
this.plugin.remakeViewPlugin();
await this.plugin.saveSettings();
});
});
new import_obsidian.Setting(containerEl).setName("Disable atomic ranges").setDesc(createFragment((el) => {
el.createSpan({ text: 'If turned on, atomic ranges to treat each of "' });
el.createEl("code", { text: "${} " });
el.createSpan({ text: '" or "' });
el.createEl("code", { text: " {}$" });
el.createSpan({ text: '" as one character are disabled.' });
})).addToggle((toggle) => {
toggle.setValue(this.plugin.settings.disableAtomicRanges).onChange(async (disable) => {
this.plugin.settings.disableAtomicRanges = disable;
this.plugin.remakeViewPlugin();
await this.plugin.saveSettings();
});
});
new import_obsidian.Setting(containerEl).addButton((button) => {
button.setButtonText("Restore defaults").onClick(async () => {
this.plugin.settings = Object.assign({}, DEFAULT_SETTINGS);
await this.plugin.saveSettings();
this.display();
});
});
}
};
// src/cleaner.ts
var import_language2 = require("@codemirror/language");
// src/utils.ts
var import_language = require("@codemirror/language");
var INLINE_MATH_BEGIN = "formatting_formatting-math_formatting-math-begin_keyword_math";
var MATH_END = "formatting_formatting-math_formatting-math-end_keyword_math_math-";
function nodeText(node, state) {
return state.sliceDoc(node.from, node.to);
}
function isInlineMathBegin(node, state) {
return node.name == INLINE_MATH_BEGIN && nodeText(node, state) == "$";
}
function isInlineMathEnd(node, state) {
return node.name == MATH_END && nodeText(node, state) == "$";
}
function selectionSatisfies(state, predicate) {
let ret = false;
const tree = (0, import_language.syntaxTree)(state);
for (const { from, to } of state.selection.ranges) {
const line = state.doc.lineAt(from);
tree.iterate({
from: line.from,
to: line.to,
enter: (node) => {
if (predicate(node)) {
ret = true;
}
}
});
}
return ret;
}
// src/cleaner.ts
function cleaner(view) {
const changes = [];
(0, import_language2.syntaxTree)(view.state).iterate({
enter(node) {
if (isInlineMathBegin(node, view.state)) {
if (view.state.sliceDoc(node.to, node.to + 3) == "{} ") {
changes.push({ from: node.to, to: node.to + 3 });
}
} else if (isInlineMathEnd(node, view.state)) {
if (view.state.sliceDoc(node.from - 3, node.from) == " {}") {
changes.push({ from: node.from - 3, to: node.from });
}
}
}
});
view.dispatch({ changes });
}
function cleanerCallback(editor) {
const view = editor.cm;
if (view) {
cleaner(view);
}
}
// src/decoration-and-atomic-range.ts
var import_state = require("@codemirror/state");
var import_view = require("@codemirror/view");
var import_language3 = require("@codemirror/language");
var DummyRangeValue = class extends import_state.RangeValue {
};
var createViewPlugin = (plugin) => import_view.ViewPlugin.fromClass(
class {
constructor(view) {
this.impl(view);
}
update(update) {
this.impl(update.view);
}
impl(view) {
const decorationBulder = new import_state.RangeSetBuilder();
const atomicRangeBulder = new import_state.RangeSetBuilder();
const tree = (0, import_language3.syntaxTree)(view.state);
for (const { from, to } of view.visibleRanges) {
tree.iterate({
from,
to,
enter(node) {
if (isInlineMathBegin(node, view.state)) {
if (view.state.sliceDoc(node.to, node.to + 3) == "{} ") {
decorationBulder.add(
node.to,
node.to + 3,
import_view.Decoration.replace({})
);
atomicRangeBulder.add(
node.from,
node.to + 3,
new DummyRangeValue()
);
}
} else if (isInlineMathEnd(node, view.state)) {
if (view.state.sliceDoc(node.from - 3, node.from) == " {}") {
decorationBulder.add(
node.from - 3,
node.from,
import_view.Decoration.replace({})
);
atomicRangeBulder.add(
node.from - 3,
node.to,
new DummyRangeValue()
);
}
}
}
});
}
this.decorations = decorationBulder.finish();
this.atomicRanges = atomicRangeBulder.finish();
}
},
{
decorations: (instance) => plugin.settings.disableDecorations ? import_view.Decoration.none : instance.decorations,
provide: (viewPlugin) => import_view.EditorView.atomicRanges.of((view) => {
var _a, _b;
return plugin.settings.disableAtomicRanges ? import_state.RangeSet.empty : (_b = (_a = view.plugin(viewPlugin)) == null ? void 0 : _a.atomicRanges) != null ? _b : import_state.RangeSet.empty;
})
}
);
// src/transaction-filter.ts
var import_state3 = require("@codemirror/state");
var import_language5 = require("@codemirror/language");
// src/latex-suite.ts
var import_state2 = require("@codemirror/state");
var import_language4 = require("@codemirror/language");
function handleLatexSuite(tr, plugin) {
if (tr.docChanged && !tr.selection) {
const changes = handleLatexSuiteBoxing(tr.startState, tr.changes);
if (changes) {
plugin._latexSuiteBoxing = true;
return { changes };
}
} else if (!tr.docChanged && tr.selection) {
if (plugin._latexSuiteBoxing) {
plugin._latexSuiteBoxing = false;
return { selection: { anchor: tr.selection.main.anchor - 3 } };
} else {
const selection = handleLatexSuiteTabout(tr.startState, tr.selection);
return [tr, { selection }];
}
}
}
function handleLatexSuiteTabout(state, newSelection) {
const tree = (0, import_language4.syntaxTree)(state);
const doc = state.doc.toString();
const newRanges = [];
for (let i = 0; i < newSelection.ranges.length; i++) {
const range = newSelection.ranges[i];
const indexNextDollar = doc.indexOf("$", range.to);
if (indexNextDollar >= 0) {
const node = tree.cursorAt(indexNextDollar, 1).node;
if (range.from === range.to && range.to === indexNextDollar && isInlineMathEnd(node, state) && state.sliceDoc(node.from - 3, node.from) === " {}") {
newRanges.push(import_state2.EditorSelection.cursor(node.to));
continue;
}
}
newRanges.push(range);
}
return import_state2.EditorSelection.create(newRanges, newSelection.mainIndex);
}
function handleLatexSuiteBoxing(state, changes) {
const tree = (0, import_language4.syntaxTree)(state);
let changeToReplace;
changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
if (inserted.toString() === "\\boxed{" + state.sliceDoc(fromA, toA) + "}") {
const nodeFrom = tree.cursorAt(fromA, -1).node;
const nodeTo = tree.cursorAt(toA, 1).node;
if (isInlineMathBegin(nodeFrom, state) && isInlineMathEnd(nodeTo, state)) {
if (state.sliceDoc(fromA, fromA + 3) === "{} " && state.sliceDoc(toA - 3, toA) === " {}") {
changeToReplace = { from: fromA, to: toA, insert: "\\boxed{" + state.sliceDoc(fromA + 3, toA - 3) + "}" };
}
}
}
});
return changeToReplace;
}
// src/transaction-filter.ts
var makeTransactionFilter = (plugin) => {
return import_state3.EditorState.transactionFilter.of((tr) => {
var _a;
if (plugin.shouldIgnore(tr.startState))
return tr;
const userEvent = (_a = tr.annotation(import_state3.Transaction.userEvent)) == null ? void 0 : _a.split(".")[0];
if (userEvent === "input") {
const changes = getChangesForInsertion(tr.startState, tr.changes);
return [tr, { changes }];
} else if (userEvent === "select" && tr.selection) {
const changes = getChangesForSelection(tr.startState, tr.selection);
return [tr, { changes }];
} else if (userEvent === "delete") {
const changes = getChangesForDeletion(tr.startState);
return [tr, { changes }];
} else if (userEvent === void 0) {
const spec = handleLatexSuite(tr, plugin);
if (spec)
return spec;
}
return tr;
});
};
function getChangesForDeletion(state) {
const tree = (0, import_language5.syntaxTree)(state);
const doc = state.doc.toString();
const changes = [];
for (const range of state.selection.ranges) {
const from = range.empty ? range.from - 4 : range.from;
const to = range.to;
const text = state.sliceDoc(from, to);
const index = text.lastIndexOf("$");
if (index == -1) {
continue;
}
const indexNextDollar = doc.indexOf("$", from + index + 1);
const indexPrevDollar = doc.lastIndexOf("$", from);
tree.iterate({
from: indexPrevDollar,
to: indexNextDollar >= 0 ? indexNextDollar : to,
enter(node) {
if (isInlineMathBegin(node, state) && state.sliceDoc(node.to, node.to + 3) == "{} ") {
changes.push({ from: node.to, to: node.to + 3 });
} else if (isInlineMathEnd(node, state) && state.sliceDoc(node.from - 3, node.from) == " {}") {
changes.push({ from: node.from - 3, to: node.from });
}
}
});
}
return changes;
}
function getChangesForInsertion(state, changes) {
const tree = (0, import_language5.syntaxTree)(state);
const doc = state.doc.toString();
const changesToAdd = [];
const beginningOfChanges = /* @__PURE__ */ new Map();
changes.iterChangedRanges((fromA, toA, fromB, toB) => {
beginningOfChanges.set(fromA, true);
});
for (const range of state.selection.ranges) {
if (range.from >= 1) {
const indexPrevDollar = doc.lastIndexOf("$", range.from - 1);
if (indexPrevDollar >= 0) {
const node = tree.cursorAt(indexPrevDollar, 1).node;
if (isInlineMathBegin(node, state)) {
if (indexPrevDollar === range.from - 1 && beginningOfChanges.has(range.from)) {
changesToAdd.push({ from: indexPrevDollar, to: range.from, insert: "${} " });
continue;
}
if (state.sliceDoc(node.to, node.to + 3) !== "{} ") {
changesToAdd.push({ from: node.to, insert: "{} " });
}
} else if (isInlineMathEnd(node, state) && state.sliceDoc(node.from - 3, node.from) === " {}") {
const openIndex = doc.lastIndexOf("${} ", node.from - 3);
changesToAdd.push({ from: openIndex + 1, to: node.from, insert: doc.slice(openIndex + 4, node.from - 3).trim() });
}
}
}
const indexNextDollar = doc.indexOf("$", range.to);
if (indexNextDollar >= 0) {
const node = tree.cursorAt(indexNextDollar, 1).node;
if (isInlineMathEnd(node, state)) {
if (state.sliceDoc(node.from - 3, node.from) !== " {}") {
changesToAdd.push({ from: node.from, insert: " {}" });
}
} else if (isInlineMathBegin(node, state) && state.sliceDoc(node.to, node.to + 3) === "{} ") {
const closeIndex = doc.indexOf(" {}$", node.to + 3);
if (closeIndex >= 0) {
changesToAdd.push({ from: node.to, to: closeIndex + 3, insert: doc.slice(node.to + 3, closeIndex).trim() });
}
}
}
}
return changesToAdd;
}
function getChangesForSelection(state, newSelection) {
const tree = (0, import_language5.syntaxTree)(state);
const doc = state.doc.toString();
const changes = [];
for (let i = 0; i < newSelection.ranges.length; i++) {
const range = newSelection.ranges[i];
const indexNextDollar = doc.indexOf("$", range.to);
const indexPrevDollar = doc.lastIndexOf("$", range.from - 1);
if (indexPrevDollar >= 0) {
const node = tree.cursorAt(indexPrevDollar, 1).node;
if (isInlineMathEnd(node, state) && state.sliceDoc(node.from - 3, node.from) === " {}") {
const openIndex = doc.lastIndexOf("${} ", node.from - 3);
changes.push({ from: openIndex + 1, to: node.from, insert: doc.slice(openIndex + 4, node.from - 3).trim() });
}
}
if (indexNextDollar >= 0) {
const node = tree.cursorAt(indexNextDollar, 1).node;
if (isInlineMathBegin(node, state) && state.sliceDoc(node.to, node.to + 3) === "{} ") {
const closeIndex = doc.indexOf(" {}$", node.to + 3);
if (closeIndex >= 0) {
changes.push({ from: node.to, to: closeIndex + 3, insert: doc.slice(node.to + 3, closeIndex).trim() });
}
}
}
}
return changes;
}
// src/main.ts
var NoMoreFlicker = class extends import_obsidian2.Plugin {
constructor() {
super(...arguments);
/**
* a view plugin that provides
* - decorations to hide braces adjacent to "$"s
* - & atomic ranges to treat each of "${} " and " {}$" as one character
*/
this.viewPlugin = [];
/**
* Indicates whether the previous transaction was the first of the two transactions
* (1. text replacement & 2. cursor position change) that Latex Suite's "box current equation"
* command produces or not. See the commend in the makeTransactionFilter() method for details.
*/
this._latexSuiteBoxing = false;
}
async onload() {
await this.loadSettings();
await this.saveSettings();
this.addSettingTab(new NoMoreFlickerSettingTab(this.app, this));
this.registerEditorExtension(this.viewPlugin);
this.remakeViewPlugin();
this.registerEditorExtension(makeTransactionFilter(this));
this.addCommand({
id: "clean",
name: "Clean up braces in this note",
editorCallback: cleanerCallback
});
this.addCommand({
id: "clean-all",
name: "Clean up braces in all the opened notes",
editorCallback: this.cleanAllMarkdownViews.bind(this)
});
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
shouldIgnore(state) {
return this.settings.disableInTable && selectionSatisfies(
state,
(node) => node.name.includes("HyperMD-table") || node.name.includes("hmd-table")
);
}
cleanAllMarkdownViews() {
this.app.workspace.iterateAllLeaves((leaf) => {
if (leaf.view instanceof import_obsidian2.MarkdownView) {
cleanerCallback(leaf.view.editor);
}
});
}
remakeViewPlugin() {
this.viewPlugin.length = 0;
this.viewPlugin.push(createViewPlugin(this));
this.app.workspace.updateOptions();
}
};

View File

@@ -0,0 +1,11 @@
{
"id": "inline-math",
"name": "No more flickering inline math",
"version": "0.3.4",
"minAppVersion": "1.3.0",
"description": "No longer disturbed by flickering inline math in Obsidian.",
"author": "Ryota Ushio",
"authorUrl": "https://github.com/RyotaUshio",
"fundingUrl": "https://www.buymeacoffee.com/ryotaushio",
"isDesktopOnly": false
}

View File

@@ -0,0 +1,467 @@
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/main.ts
var main_exports = {};
__export(main_exports, {
default: () => MathInCalloutPlugin
});
module.exports = __toCommonJS(main_exports);
var import_obsidian3 = require("obsidian");
// src/decorations.ts
var import_state2 = require("@codemirror/state");
var import_language2 = require("@codemirror/language");
var import_view = require("@codemirror/view");
var import_obsidian = require("obsidian");
// src/quote-field.ts
var import_language = require("@codemirror/language");
var import_state = require("@codemirror/state");
var QuoteInfo = class extends import_state.RangeValue {
/**
* @param level The level of the blockquote/callout (i.e. the number of ">"s).
* @param isBaseCallout True if this is a callout or this is nested inside a callout of level 1.
*/
constructor(level, isBaseCallout) {
super();
this.level = level;
this.isBaseCallout = isBaseCallout;
this.pattern = this.level > 0 ? new RegExp(`^( {0,3}>){${this.level}}`) : null;
}
eq(other) {
return this.level === other.level && this.isBaseCallout === other.isBaseCallout;
}
/** Remove ">"s that is misrecognized as inequality signs. */
correctMath(math) {
if (!this.pattern)
return math;
const lines = math.split("\n");
return lines.map((line) => {
const match = line.match(this.pattern);
return match ? line.slice(match[0].length) : line;
}).join("\n");
}
getBlockquoteBorderPositions(state, from, to) {
const positions = [];
const lineBegin = state.doc.lineAt(from);
const lineEnd = state.doc.lineAt(to);
for (let i = lineBegin.number; i <= lineEnd.number; i++) {
const line = state.doc.line(i);
let start = 0;
for (let i2 = 0; i2 < this.level; i2++) {
const index = line.text.indexOf(">", start);
if (index === -1)
continue;
positions.push({ pos: index + line.from, first: i2 === 0 });
start = index + 1;
}
}
return positions;
}
};
var quoteInfoField = import_state.StateField.define({
create(state) {
return parseBlockquotes(state);
},
update(prev, tr) {
return tr.docChanged ? parseBlockquotes(tr.state) : prev;
}
});
function parseBlockquotes(state) {
const tree = (0, import_language.syntaxTree)(state);
const builder = new import_state.RangeSetBuilder();
let level = 0;
let from = -1;
let isBaseCallout = false;
for (let i = 1; i <= state.doc.lines; i++) {
const line = state.doc.line(i);
const match = line.text.match(/^( {0,3}>)+/);
const newLevel = match ? match[0].split(">").length - 1 : 0;
if (newLevel !== level) {
if (level === 0 && newLevel === 1) {
isBaseCallout = tree.cursorAt(line.from, 1).node.name.contains("-callout");
}
if (level > 0 && from >= 0) {
builder.add(from, line.from, new QuoteInfo(level, isBaseCallout));
}
level = newLevel;
from = line.from;
}
}
if (level > 0 && from >= 0) {
builder.add(from, state.doc.length, new QuoteInfo(level, isBaseCallout));
}
return builder.finish();
}
// src/utils.ts
function getQuoteInfo(state, pos) {
const field = state.field(quoteInfoField, false);
if (!field)
return null;
const { from, to, value } = field.iter(pos);
if (from <= pos && pos <= to)
return value;
return null;
}
function hasOverlap(range, start, to) {
return range.from <= to && range.to >= start;
}
function rangesHaveOverlap(ranges, start, to) {
for (const range of ranges) {
if (hasOverlap(range, start, to))
return true;
}
return false;
}
// src/decorations.ts
var createCalloutDecorator = (BuiltInMathWidget) => import_state2.StateField.define({
create() {
return import_view.Decoration.none;
},
update(prev, tr) {
const { state } = tr;
const view = state.field(import_obsidian.editorEditorField);
if (view.composing)
return prev.map(tr.changes);
const isSourceMode = !state.field(import_obsidian.editorLivePreviewField);
const doc = state.doc;
const ranges = view.hasFocus ? state.selection.ranges : [];
const tree = (0, import_language2.syntaxTree)(state);
const decorations = [];
const makeDeco = (decorationSpec, from, to) => {
if (decorationSpec.block && to === doc.length)
decorationSpec.inclusiveEnd = false;
return import_view.Decoration.replace(decorationSpec);
};
let mathBegin = -1;
let mathContentBegin = -1;
let block = false;
tree.iterate({
enter(node) {
if (node.name.contains("formatting-math-begin")) {
mathBegin = node.from;
mathContentBegin = node.to;
block = node.name.contains("math-block");
} else if (mathBegin !== -1) {
if (node.name.contains("formatting-math-end")) {
const mathContentEnd = node.from;
const mathEnd = node.to;
let math = doc.sliceString(mathContentBegin, mathContentEnd);
const quote = getQuoteInfo(state, mathContentBegin);
if (quote)
math = quote.correctMath(math);
const widget = new BuiltInMathWidget(math, block);
if (quote)
widget.markAsCorrected();
widget.setPos(
block && math.startsWith("\n") ? mathContentBegin + 1 : mathContentBegin,
block && math.endsWith("\n") ? mathContentEnd - 1 : mathContentEnd
);
const overlap = rangesHaveOverlap(ranges, mathBegin, mathEnd);
if (block && quote && quote.level > 0) {
if (isSourceMode || quote.isBaseCallout || overlap) {
const lineBegin = state.doc.lineAt(mathBegin);
const lineEnd = state.doc.lineAt(mathEnd);
for (let i = lineBegin.number; i <= lineEnd.number; i++) {
const line = state.doc.line(i);
decorations.push(
import_view.Decoration.line({ class: "HyperMD-quote" }).range(line.from, line.from)
);
const transparent = !isSourceMode && !rangesHaveOverlap(ranges, line.from, line.to);
let start = 0;
for (let i2 = 0; i2 < quote.level; i2++) {
const index = line.text.indexOf(">", start);
if (index === -1)
continue;
const pos = index + line.from;
if (i2 === 0) {
decorations.push(
import_view.Decoration.mark({ class: transparent ? "cm-transparent" : "cm-quote cm-formatting-quote" }).range(pos, pos + 1)
);
} else {
decorations.push(
import_view.Decoration.mark({ class: transparent ? "cm-blockquote-border cm-transparent" : "cm-quote cm-formatting-quote" }).range(pos, pos + 1)
);
}
start = index + 1;
}
}
if (lineEnd.from < mathContentEnd && lineEnd.text.slice(0, mathContentEnd - lineEnd.from).split(">").every((s) => !s.trim())) {
decorations.push(
import_view.Decoration.mark({ class: "cancel-cm-math" }).range(lineEnd.from, mathContentEnd)
);
}
}
}
if (!isSourceMode && (quote == null ? void 0 : quote.isBaseCallout)) {
if (overlap) {
if (block) {
decorations.push(
import_view.Decoration.widget({
widget,
block: false,
side: 1
}).range(mathEnd, mathEnd)
);
}
} else {
decorations.push(
makeDeco({
widget,
block: false
}, mathBegin, mathEnd).range(mathBegin, mathEnd)
);
}
}
mathBegin = -1;
mathContentBegin = -1;
}
}
}
});
return import_view.Decoration.set(decorations, true);
},
provide(field) {
return import_view.EditorView.decorations.from(field);
}
});
// src/patch-widget-type.ts
var import_view2 = require("@codemirror/view");
var import_view3 = require("@codemirror/view");
// node_modules/monkey-around/mjs/index.js
function around(obj, factories) {
const removers = Object.keys(factories).map((key) => around1(obj, key, factories[key]));
return removers.length === 1 ? removers[0] : function() {
removers.forEach((r) => r());
};
}
function around1(obj, method, createWrapper) {
const original = obj[method], hadOwn = obj.hasOwnProperty(method);
let current = createWrapper(original);
if (original)
Object.setPrototypeOf(current, original);
Object.setPrototypeOf(wrapper, current);
obj[method] = wrapper;
return remove;
function wrapper(...args) {
if (current === original && obj[method] === wrapper)
remove();
return current.apply(this, args);
}
function remove() {
if (obj[method] === wrapper) {
if (hadOwn)
obj[method] = original;
else
delete obj[method];
}
if (current === original)
return;
current = original;
Object.setPrototypeOf(wrapper, original || Function);
}
}
// src/patch-widget-type.ts
var patchDecoration = (plugin, onPatched) => {
const uninstaller = around(import_view2.Decoration, {
replace(old) {
return function(spec) {
if (!plugin.patchSucceeded && spec.widget) {
plugin.patchSucceeded = patchMathWidget(plugin, spec.widget);
if (plugin.patchSucceeded) {
onPatched(spec.widget.constructor);
uninstaller();
}
}
return old.call(this, spec);
};
},
widget(old) {
return function(spec) {
if (!plugin.patchSucceeded && spec.widget) {
plugin.patchSucceeded = patchMathWidget(plugin, spec.widget);
if (plugin.patchSucceeded) {
onPatched(spec.widget.constructor);
uninstaller();
}
}
return old.call(this, spec);
};
}
});
plugin.register(uninstaller);
};
function patchMathWidget(plugin, widget) {
const proto = widget.constructor.prototype;
const superProto = Object.getPrototypeOf(proto);
const superSuperProto = Object.getPrototypeOf(superProto);
const isObsidianBuiltinMathWidget = Object.hasOwn(widget, "math") && Object.hasOwn(widget, "block") && Object.hasOwn(proto, "eq") && Object.hasOwn(proto, "initDOM") && Object.hasOwn(proto, "patchDOM") && Object.hasOwn(proto, "render") && !Object.hasOwn(proto, "toDOM") && !Object.hasOwn(proto, "updateDOM") && Object.hasOwn(superProto, "become") && Object.hasOwn(superProto, "updateDOM") && Object.hasOwn(superSuperProto, "addEditButton") && Object.hasOwn(superSuperProto, "hookClickHandler") && Object.hasOwn(superSuperProto, "resizeWidget") && Object.hasOwn(superSuperProto, "setOwner") && Object.hasOwn(superSuperProto, "setPos") && Object.hasOwn(superSuperProto, "toDOM") && Object.getPrototypeOf(superSuperProto) === import_view3.WidgetType.prototype;
if (isObsidianBuiltinMathWidget) {
plugin.register(around(proto, {
/** Newly added by this plugin: Get a quote info for the position of this math widget. */
getQuoteInfo() {
return function() {
return this.view ? getQuoteInfo(this.view.state, this.start - 1) : null;
};
},
/** Newly added by this plugin */
markAsCorrected() {
return function() {
this.corrected = true;
};
},
/**
* Newly added by this plugin: Correct the LaTeX source code (this.math)
* based on the quote info, i.e. remove an appropreate number of ">"s
* at the head of each line.
*/
correctIfNecessary() {
return function() {
if (this.block && !this.corrected) {
const quote = this.getQuoteInfo();
if (quote) {
this.math = quote.correctMath(this.math);
this.markAsCorrected();
}
}
};
},
eq(old) {
return function(other) {
if (this.block && other.block) {
if (this.view && !other.view)
other.view = this.view;
if (other.view && !this.view)
this.view = other.view;
if (!this.corrected)
this.correctIfNecessary();
if (!other.corrected)
other.correctIfNecessary();
}
return old.call(this, other);
};
},
initDOM(old) {
return function(view) {
if (!this.view)
this.view = view;
return old.call(this, view);
};
},
patchDOM(old) {
return function(dom, view) {
if (!this.view)
this.view = view;
return old.call(this, dom, view);
};
},
render(old) {
return function(dom) {
this.correctIfNecessary();
old.call(this, dom);
};
}
}));
return true;
}
return false;
}
// src/settings.ts
var import_obsidian2 = require("obsidian");
var DEFAULT_SETTINGS = {
notification: true
};
var MathInCalloutSettingTab = class extends import_obsidian2.PluginSettingTab {
constructor(plugin) {
super(plugin.app, plugin);
this.plugin = plugin;
}
display() {
this.containerEl.empty();
new import_obsidian2.Setting(this.containerEl).setDesc("If something is not working, type some math expression outside callouts in Live Preview.");
new import_obsidian2.Setting(this.containerEl).setName("Show setup guidance notifications").addToggle((toggle) => {
toggle.setValue(this.plugin.settings.notification).onChange(async (value) => {
this.plugin.settings.notification = value;
await this.plugin.saveSettings();
this.plugin.showNotReadyNotice();
});
});
}
};
// src/main.ts
var MathInCalloutPlugin = class extends import_obsidian3.Plugin {
constructor() {
super(...arguments);
this.notReadyNotice = null;
}
async onload() {
await this.loadSettings();
await this.saveSettings();
this.addSettingTab(new MathInCalloutSettingTab(this));
this.patchSucceeded = false;
this.registerEditorExtension(quoteInfoField);
this.app.workspace.onLayoutReady(() => setTimeout(() => this.showNotReadyNotice(), 1e3));
patchDecoration(this, (builtInMathWidget) => {
setTimeout(() => {
if (this.notReadyNotice) {
this.notReadyNotice.hide();
this.notReadyNotice = null;
if (this.settings.notification) {
new import_obsidian3.Notice(`${this.manifest.name}: You're ready! (Note: this notifiction can be turned off in the plugin setting.)`, 1500);
}
}
this.registerEditorExtension(createCalloutDecorator(builtInMathWidget));
this.rerender();
}, 100);
});
}
rerender() {
this.app.workspace.iterateAllLeaves((leaf) => {
if (leaf.view instanceof import_obsidian3.MarkdownView) {
const eState = leaf.view.getEphemeralState();
const editor = leaf.view.editor;
editor.setValue(editor.getValue());
leaf.view.setEphemeralState(eState);
}
});
}
showNotReadyNotice() {
if (!this.patchSucceeded && this.settings.notification) {
this.notReadyNotice = new import_obsidian3.Notice(`${this.manifest.name}: You're not ready yet. In Live Preview, type some math expression outside callouts.`, 0);
}
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
};

View File

@@ -0,0 +1,11 @@
{
"id": "math-in-callout",
"name": "Better Math in Callouts & Blockquotes",
"version": "0.3.7",
"minAppVersion": "1.3.15",
"description": "Add better Live Preview support for math rendering inside callouts & blockquotes.",
"author": "Ryota Ushio",
"authorUrl": "https://github.com/RyotaUshio",
"fundingUrl": "https://www.buymeacoffee.com/ryotaushio",
"isDesktopOnly": false
}

View File

@@ -0,0 +1,9 @@
/* .cm-math:has(.cm-quote.cm-formatting-quote) */
/* .cm-math:has(.cm-blockquote-border) */
/* { */
/* all: unset; */
/* } */
.cm-math:has( .cancel-cm-math) {
all: unset;
}

View File

@@ -43,7 +43,7 @@
"singlelineCardSeparator": "::",
"singlelineReversedCardSeparator": ":::"
},
"buryDate": "2024-03-30",
"buryDate": "2024-04-01",
"buryList": [],
"historyDeck": ""
}

View File

@@ -1,5 +1,5 @@
{
"displayIndividualItems": false,
"displayIndividualItems": true,
"showNotes": true,
"showAttachments": true,
"showFiles": true,

View File

@@ -8,6 +8,10 @@
],
"pluginSubListFrozenVersion": [],
"themesList": [
{
"repo": "Bluemoondragon07/Wikipedia-Theme",
"lastUpdate": "90496471"
},
{
"repo": "AnubisNekhet/AnuPpuccin",
"lastUpdate": "2022-11-24T13:06:17Z"
@@ -15,10 +19,11 @@
],
"updateAtStartup": false,
"updateThemesAtStartup": false,
"ribbonIconEnabled": true,
"enableAfterInstall": true,
"loggingEnabled": false,
"loggingPath": "BRAT-log",
"loggingVerboseEnabled": false,
"debuggingMode": true,
"notificationsEnabled": true
"notificationsEnabled": true,
"ribbonIconEnabled": true
}

View File

@@ -0,0 +1,10 @@
{
"modifier": "Alt",
"lazyHide": true,
"position": "Auto",
"customPositionX": 0,
"customPositionY": 0,
"stickToMouse": true,
"log": false,
"disableCloseSuggest": false
}

513
.obsidian/plugins/quick-preview/main.js vendored Normal file
View File

@@ -0,0 +1,513 @@
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
// src/main.ts
var main_exports = {};
__export(main_exports, {
default: () => QuickPreviewPlugin
});
module.exports = __toCommonJS(main_exports);
var import_obsidian5 = require("obsidian");
var import_obsidian6 = require("obsidian");
// node_modules/monkey-around/mjs/index.js
function around(obj, factories) {
const removers = Object.keys(factories).map((key) => around1(obj, key, factories[key]));
return removers.length === 1 ? removers[0] : function() {
removers.forEach((r) => r());
};
}
function around1(obj, method, createWrapper) {
const original = obj[method], hadOwn = obj.hasOwnProperty(method);
let current = createWrapper(original);
if (original)
Object.setPrototypeOf(current, original);
Object.setPrototypeOf(wrapper, current);
obj[method] = wrapper;
return remove;
function wrapper(...args) {
if (current === original && obj[method] === wrapper)
remove();
return current.apply(this, args);
}
function remove() {
if (obj[method] === wrapper) {
if (hadOwn)
obj[method] = original;
else
delete obj[method];
}
if (current === original)
return;
current = original;
Object.setPrototypeOf(wrapper, original || Function);
}
}
// src/settings.ts
var import_obsidian2 = require("obsidian");
// src/utils.ts
var import_obsidian = require("obsidian");
function getModifierNameInPlatform(mod) {
if (mod === "Mod") {
return import_obsidian.Platform.isMacOS || import_obsidian.Platform.isIosApp ? "Command" : "Ctrl";
}
if (mod === "Shift") {
return "Shift";
}
if (mod === "Alt") {
return import_obsidian.Platform.isMacOS || import_obsidian.Platform.isIosApp ? "Option" : "Alt";
}
if (mod === "Meta") {
return import_obsidian.Platform.isMacOS || import_obsidian.Platform.isIosApp ? "Command" : import_obsidian.Platform.isWin ? "Win" : "Meta";
}
return "Ctrl";
}
function getSelectedItem(suggestions) {
return suggestions.values[suggestions.selectedItem];
}
// src/settings.ts
var POSITIONS = ["Auto", "Top left", "Top right", "Bottom left", "Bottom right", "Custom"];
var DEFAULT_SETTINGS = {
modifier: "Alt",
lazyHide: true,
position: "Auto",
customPositionX: 0,
customPositionY: 0,
stickToMouse: true,
log: false,
disableCloseSuggest: false
};
var QuickPreviewSettingTab = class extends import_obsidian2.PluginSettingTab {
constructor(plugin) {
super(plugin.app, plugin);
this.plugin = plugin;
}
addTextSetting(settingName) {
return new import_obsidian2.Setting(this.containerEl).addText((text) => {
text.setValue(this.plugin.settings[settingName]).setPlaceholder(DEFAULT_SETTINGS[settingName]).onChange(async (value) => {
this.plugin.settings[settingName] = value;
await this.plugin.saveSettings();
});
});
}
addNumberSetting(settingName) {
return new import_obsidian2.Setting(this.containerEl).addText((text) => {
text.setValue("" + this.plugin.settings[settingName]).setPlaceholder("" + DEFAULT_SETTINGS[settingName]).then((text2) => text2.inputEl.type = "number").onChange(async (value) => {
this.plugin.settings[settingName] = value === "" ? DEFAULT_SETTINGS[settingName] : +value;
await this.plugin.saveSettings();
});
});
}
addToggleSetting(settingName, extraOnChange) {
return new import_obsidian2.Setting(this.containerEl).addToggle((toggle) => {
toggle.setValue(this.plugin.settings[settingName]).onChange(async (value) => {
this.plugin.settings[settingName] = value;
await this.plugin.saveSettings();
extraOnChange == null ? void 0 : extraOnChange(value);
});
});
}
addDropdowenSetting(settingName, options, display, extraOnChange) {
return new import_obsidian2.Setting(this.containerEl).addDropdown((dropdown) => {
var _a;
const displayNames = /* @__PURE__ */ new Set();
for (const option of options) {
const displayName = (_a = display == null ? void 0 : display(option)) != null ? _a : option;
if (!displayNames.has(displayName)) {
dropdown.addOption(option, displayName);
displayNames.add(displayName);
}
}
dropdown.setValue(this.plugin.settings[settingName]).onChange(async (value) => {
this.plugin.settings[settingName] = value;
await this.plugin.saveSettings();
extraOnChange == null ? void 0 : extraOnChange(value);
});
});
}
addSliderSetting(settingName, min, max, step) {
return new import_obsidian2.Setting(this.containerEl).addSlider((slider) => {
slider.setLimits(min, max, step).setValue(this.plugin.settings[settingName]).setDynamicTooltip().onChange(async (value) => {
this.plugin.settings[settingName] = value;
await this.plugin.saveSettings();
});
});
}
display() {
this.containerEl.empty();
this.addDropdowenSetting("modifier", ["Mod", "Ctrl", "Meta", "Shift", "Alt"], getModifierNameInPlatform).setName("Modifier key to toggle quick preview").setDesc("Hold down this key to preview a suggestion before selecting it.");
this.addDropdowenSetting("position", POSITIONS, void 0, () => this.display()).setName("Quick preview position").setDesc("Where to show the quick preview.");
if (this.plugin.settings.position === "Custom") {
this.addNumberSetting("customPositionX").setName("Custom x coordinate").setDesc("Offset relative to the left edge of the window.");
this.addNumberSetting("customPositionY").setName("Custom y coordinate").setDesc("Offset relative to the top edge of the window.");
}
this.addToggleSetting("stickToMouse").setName("Stick to mouse position").setDesc("If turned on, the preview popover will follow the mouse pointer.");
this.addToggleSetting("lazyHide").setName("Don't close the current preview until the next preview is ready").setDesc("If turned on, pressing arrow keys or hovering the mouse pointer over a suggestion while holding the modifier key will not immediately close the preview, but instead wait for the preview for the newly selected suggestion to load.");
new import_obsidian2.Setting(this.containerEl).setName("Debug mode (advanced)").setHeading();
this.addToggleSetting("log").setName("Show selected suggestion in console");
this.addToggleSetting("disableCloseSuggest", (disable) => {
const suggest = this.plugin.getBuiltInSuggest();
if (!disable && suggest.isOpen)
suggest.close();
}).setName("Prevent the suggestion box from closing").setDesc("Useful for inspecting the suggestion box DOM.");
}
};
// src/popoverManager.ts
var import_obsidian3 = require("obsidian");
// src/hoverParent.ts
var _hoverPopover;
var QuickPreviewHoverParent = class {
constructor(suggest) {
this.suggest = suggest;
__privateAdd(this, _hoverPopover, null);
this.hidden = false;
this.manager = this.suggest.popoverManager;
}
hide() {
var _a;
(_a = this.hoverPopover) == null ? void 0 : _a.hide();
this.hidden = true;
if (this.manager.currentOpenHoverParent === this) {
this.manager.currentOpenHoverParent = null;
}
}
get hoverPopover() {
return __privateGet(this, _hoverPopover);
}
set hoverPopover(hoverPopover) {
var _a;
__privateSet(this, _hoverPopover, hoverPopover);
if (__privateGet(this, _hoverPopover)) {
this.manager.addChild(__privateGet(this, _hoverPopover));
(_a = this.manager.currentOpenHoverParent) == null ? void 0 : _a.hide();
this.manager.currentOpenHoverParent = this;
if (this.hidden) {
this.hide();
return;
}
__privateGet(this, _hoverPopover).hoverEl.addClass("quick-preview");
__privateGet(this, _hoverPopover).position(__privateGet(this, _hoverPopover).shownPos = this.manager.getShownPos());
}
}
};
_hoverPopover = new WeakMap();
// src/popoverManager.ts
var PopoverManager = class extends import_obsidian3.Component {
constructor(plugin, suggest, itemNormalizer) {
super();
this.plugin = plugin;
this.suggest = suggest;
this.itemNormalizer = itemNormalizer;
this.currentHoverParent = null;
this.currentOpenHoverParent = null;
this.lastEvent = null;
this.handlers = [];
this.popoverHeight = null;
this.popoverWidth = null;
if (suggest instanceof import_obsidian3.PopoverSuggest)
this.suggestions = suggest.suggestions;
else
this.suggestions = suggest.chooser;
}
onload() {
this.registerDomEvent(window, "keydown", (event) => {
if (this.suggest.isOpen && import_obsidian3.Keymap.isModifier(event, this.plugin.settings.modifier)) {
if (this.currentOpenHoverParent)
this.hide();
else {
const item = getSelectedItem(this.suggestions);
if (item)
this.spawnPreview(item);
}
}
});
this.registerDomEvent(window, "keyup", (event) => {
if (event.key === this.plugin.settings.modifier)
this.hide();
});
this.registerDomEvent(window, "mousemove", (event) => {
if (!import_obsidian3.Keymap.isModifier(event, this.plugin.settings.modifier))
this.hide();
});
this.handlers.push(
this.suggest.scope.register([this.plugin.settings.modifier], "ArrowUp", (event) => {
this.suggestions.moveUp(event);
return false;
}),
this.suggest.scope.register([this.plugin.settings.modifier], "ArrowDown", (event) => {
this.suggestions.moveDown(event);
return false;
})
);
}
onunload() {
var _a, _b;
this.handlers.forEach((handler) => {
this.suggest.scope.unregister(handler);
});
this.handlers.length = 0;
(_a = this.currentHoverParent) == null ? void 0 : _a.hide();
this.currentHoverParent = null;
(_b = this.currentOpenHoverParent) == null ? void 0 : _b.hide();
this.currentOpenHoverParent = null;
this.lastEvent = null;
}
hide(lazy = false) {
var _a;
if (!lazy)
(_a = this.currentHoverParent) == null ? void 0 : _a.hide();
this.currentHoverParent = null;
}
spawnPreview(item, lazyHide = false, event = null) {
this.hide(lazyHide);
if (event instanceof MouseEvent || event instanceof PointerEvent)
this.lastEvent = event;
this.currentHoverParent = new QuickPreviewHoverParent(this.suggest);
const info = this.itemNormalizer(item);
if (info)
this.plugin.onLinkHover(this.currentHoverParent, null, info.linktext, info.sourcePath, { scroll: info.line });
}
getShownPos() {
if (this.plugin.settings.stickToMouse && this.lastEvent)
return { x: this.lastEvent.clientX, y: this.lastEvent.clientY };
const position = this.plugin.settings.position;
if (position === "Auto") {
return this.getShownPosAuto();
} else if (position === "Custom") {
return { x: this.plugin.settings.customPositionX, y: this.plugin.settings.customPositionY };
}
return this.getShownPosCorner(position);
}
getShownPosCorner(position) {
if (position === "Top left") {
return { x: 0, y: 0 };
} else if (position === "Top right") {
return { x: window.innerWidth, y: 0 };
} else if (position === "Bottom left") {
return { x: 0, y: window.innerHeight };
}
return { x: window.innerWidth, y: window.innerHeight };
}
getShownPosAuto() {
var _a, _b, _c, _d, _e;
const el = this.suggestions.containerEl;
const { top, bottom, left, right, width, height } = el.getBoundingClientRect();
const popover = (_a = this.currentHoverParent) == null ? void 0 : _a.hoverPopover;
this.popoverWidth = (_c = (_b = popover == null ? void 0 : popover.hoverEl.offsetWidth) != null ? _b : this.popoverWidth) != null ? _c : null;
this.popoverHeight = (_e = (_d = popover == null ? void 0 : popover.hoverEl.offsetHeight) != null ? _d : this.popoverHeight) != null ? _e : null;
if (this.popoverWidth && this.popoverHeight) {
let offsetX = width * 0.1;
let offsetY = height * 0.1;
if (right - offsetX + this.popoverWidth < window.innerWidth)
return { x: right - offsetX, y: top + offsetY };
offsetX = width * 0.03;
offsetY = height * 0.05;
if (left > this.popoverWidth + offsetX)
return { x: left - this.popoverWidth - offsetX, y: top + offsetY };
}
const x = (left + right) * 0.5;
const y = (top + bottom) * 0.5;
if (x >= window.innerWidth * 0.6) {
if (y >= window.innerHeight * 0.5)
return this.getShownPosCorner("Top left");
return this.getShownPosCorner("Bottom left");
}
if (y >= window.innerHeight * 0.5)
return this.getShownPosCorner("Top right");
return this.getShownPosCorner("Bottom right");
}
};
// src/reload.ts
var import_obsidian4 = require("obsidian");
var ReloadModal = class extends import_obsidian4.Modal {
constructor(app) {
super(app);
}
onOpen() {
this.titleEl.setText("Quick Preview");
this.contentEl.setText("You need to reload the app to be able to use this plugin together with Hover Editor.");
new import_obsidian4.Setting(this.contentEl).addButton((button) => {
button.setButtonText("Reload").setCta().onClick(() => this.app.commands.executeCommandById("app:reload"));
}).addButton((button) => {
button.setButtonText("Not now").onClick(() => this.close());
});
}
onClose() {
this.contentEl.empty();
}
};
// src/main.ts
var _originalOnLinkHover;
var QuickPreviewPlugin = class extends import_obsidian6.Plugin {
constructor() {
super(...arguments);
__privateAdd(this, _originalOnLinkHover, void 0);
}
async onload() {
if (this.app.workspace.layoutReady && this.app.plugins.enabledPlugins.has("obsidian-hover-editor")) {
new ReloadModal(this.app).open();
}
__privateSet(this, _originalOnLinkHover, this.app.internalPlugins.getPluginById("page-preview").instance.onLinkHover);
await this.loadSettings();
await this.saveSettings();
this.addSettingTab(new QuickPreviewSettingTab(this));
this.app.workspace.onLayoutReady(() => {
this.patchSetSelectedItem();
this.patchSuggester(this.getBuiltInSuggest().constructor, (item) => {
if (!item.file)
return null;
const info = { linktext: item.file.path, sourcePath: "" };
if (item.type === "heading")
info.linktext += "#" + (0, import_obsidian5.stripHeadingForLink)(item.heading);
else if (item.type === "block")
info.line = item.node.position.start.line;
return info;
});
this.patchSuggester(
this.app.internalPlugins.getPluginById("switcher").instance.QuickSwitcherModal,
(item) => {
var _a;
if (!item.file)
return null;
const info = { linktext: item.file.path, sourcePath: "" };
if (item.type === "headingsList")
info.linktext += "#" + (0, import_obsidian5.stripHeadingForLink)(item.item.heading);
else if (item.type === "symbolList")
info.line = item.item.symbol.position.start.line;
else if (item.type === "bookmark" && item.item.type === "file")
info.linktext = item.item.path + ((_a = item.item.subpath) != null ? _a : "");
return info;
}
);
this.patchCanvasSuggest();
});
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
/** Call the core Page Preview plugin's (potentially) original onLinkHover method. */
onLinkHover(hoverParent, targetEl, linktext, sourcePath, state) {
const self = this.app.internalPlugins.getPluginById("page-preview").instance;
return __privateGet(this, _originalOnLinkHover).call(self, hoverParent, targetEl, linktext, sourcePath, state);
}
getBuiltInSuggest() {
return this.app.workspace.editorSuggest.suggests[0];
}
patchSetSelectedItem() {
const plugin = this;
const suggest = this.getBuiltInSuggest();
this.register(around(suggest.suggestions.constructor.prototype, {
setSelectedItem(old) {
return function(index, event) {
old.call(this, index, event);
if (this.chooser.popoverManager instanceof PopoverManager) {
const manager = this.chooser.popoverManager;
if (plugin.settings.log)
console.log(getSelectedItem(this));
if (event && import_obsidian6.Keymap.isModifier(event, plugin.settings.modifier)) {
const item = getSelectedItem(this);
if (item)
manager.spawnPreview(item, plugin.settings.lazyHide, event);
}
}
};
}
}));
}
patchSuggester(suggestClass, itemNormalizer) {
const prototype = suggestClass.prototype;
const plugin = this;
const uninstaller = around(prototype, {
open(old) {
return function() {
old.call(this);
const self = this;
if (!self.popoverManager)
self.popoverManager = new PopoverManager(plugin, self, itemNormalizer);
self.popoverManager.load();
};
},
close(old) {
return function() {
var _a;
if (plugin.settings.disableCloseSuggest)
return;
old.call(this);
(_a = this.popoverManager) == null ? void 0 : _a.unload();
};
}
});
this.register(uninstaller);
return uninstaller;
}
patchCanvasSuggest() {
const plugin = this;
const uninstaller = around(import_obsidian5.SuggestModal.prototype, {
setInstructions(old) {
return function(...args) {
old.call(this, ...args);
const proto = Object.getPrototypeOf(this);
if (this.hasOwnProperty("canvas") && proto.hasOwnProperty("showMarkdownAndCanvas") && proto.hasOwnProperty("showAttachments")) {
plugin.patchSuggester(this.constructor, (item) => {
if (!item.file)
return null;
return { linktext: item.file.path, sourcePath: "" };
});
uninstaller();
}
};
}
});
this.register(uninstaller);
}
};
_originalOnLinkHover = new WeakMap();

View File

@@ -0,0 +1,11 @@
{
"id": "quick-preview",
"name": "Quick Preview",
"version": "0.6.0",
"minAppVersion": "1.3.5",
"description": "Quickly preview a suggestion before selecting it in link suggestions & quick switcher.",
"author": "Ryota Ushio",
"authorUrl": "https://github.com/RyotaUshio",
"fundingUrl": "https://www.buymeacoffee.com/ryotaushio",
"isDesktopOnly": false
}

View File

@@ -0,0 +1,20 @@
/* @settings
name: Quick Preview
id: quick-preview
settings:
-
id: quick-preview-font-size
title: Font size (%)
type: variable-number-slider
min: 10
max: 200
step: 1
default: 100
format: "%"
*/
.popover.hover-popover.quick-preview {
--layer-popover: calc(max(var(--layer-modal), var(--layer-notice)) + 1);
--popover-font-size: var(--quick-preview-font-size);
}

View File

@@ -6,6 +6,7 @@
"minFuzzyMatchScore": 0.5,
"matchingWithoutEmoji": true,
"treatAccentDiacriticsAsAlphabeticCharacters": true,
"treatUnderscoreAsPartOfWord": false,
"maxNumberOfSuggestions": 10,
"maxNumberOfWordsAsPhrase": 3,
"minNumberOfCharactersTriggered": 1,
@@ -13,6 +14,7 @@
"complementAutomatically": true,
"delayMilliSeconds": 0,
"disableSuggestionsDuringImeOn": false,
"disableSuggestionsInMathBlock": true,
"insertAfterCompletion": true,
"firstCharactersDisableSuggestions": ":/^",
"patternsToSuppressTrigger": [
@@ -33,6 +35,13 @@
"hideHotkeyGuide": false
}
],
"select with custom alias": [
{
"modifiers": [],
"key": "ArrowRight",
"hideHotkeyGuide": false
}
],
"up": [
{
"modifiers": [],
@@ -63,7 +72,7 @@
"currentFileMinNumberOfCharacters": 0,
"onlyComplementEnglishOnCurrentFileComplement": false,
"enableCurrentVaultComplement": false,
"currentVaultMinNumberOfCharacters": 0,
"currentVaultMinNumberOfCharacters": 2,
"includeCurrentVaultPathPrefixPatterns": "",
"excludeCurrentVaultPathPrefixPatterns": "",
"includeCurrentVaultOnlyFilesUnderCurrentDirectory": false,

View File

@@ -1 +1 @@
{"matrice hessienne":{"matrice hessienne":{"internalLink":{"count":2,"lastUpdated":1710324879177}}},"manim Ellipse":{"manim Ellipse":{"internalLink":{"count":1,"lastUpdated":1709296590359}}},"baptême":{"baptême":{"internalLink":{"count":5,"lastUpdated":1709864270370}}},"gradient":{"gradient":{"internalLink":{"count":1,"lastUpdated":1710325461961}}},"obsidian plugin tag and wordcloud":{"obsidian plugin tag and wordcloud":{"internalLink":{"count":1,"lastUpdated":1710345237714}}},"intersection de sous groupes":{"intersection de sous groupes":{"internalLink":{"count":1,"lastUpdated":1710465530327}}},"valeurs":{"valeurs":{"internalLink":{"count":1,"lastUpdated":1711459246780}}},"Learning APL":{"Learning APL":{"internalLink":{"count":1,"lastUpdated":1711584419388}}},"structure de donnés":{"structure de donnés":{"internalLink":{"count":1,"lastUpdated":1711621251914}}},"paramètre":{"paramètre":{"internalLink":{"count":1,"lastUpdated":1711621492446}}},"langage de programmation":{"langage de programmation":{"internalLink":{"count":3,"lastUpdated":1711917360066}}},"argument d'une fonction":{"argument d'une fonction":{"internalLink":{"count":1,"lastUpdated":1711624010397}}},"argument":{"argument":{"internalLink":{"count":2,"lastUpdated":1711624133731}}},"techniques de pkm":{"techniques de pkm":{"internalLink":{"count":1,"lastUpdated":1711627281333}}},"paradigme de programmation":{"paradigme de programmation":{"internalLink":{"count":6,"lastUpdated":1711917618071}}},"état":{"état":{"internalLink":{"count":3,"lastUpdated":1711905774038}}},"structure de données":{"structure de données":{"internalLink":{"count":1,"lastUpdated":1711643699590}}},"structures de données":{"structures de données":{"internalLink":{"count":2,"lastUpdated":1711904665130}}},"enregistrement":{"enregistrement":{"internalLink":{"count":1,"lastUpdated":1711668283936}}},"envoi de messages entre objets":{"envoi de messages entre objets":{"internalLink":{"count":1,"lastUpdated":1711742931869}}},"programmation structurée":{"programmation structurée":{"internalLink":{"count":1,"lastUpdated":1711764089506}}},"effet de bord":{"effet de bord":{"internalLink":{"count":2,"lastUpdated":1711906516742}}},"programmation impérative":{"programmation impérative":{"internalLink":{"count":3,"lastUpdated":1711915570179}}},"composition de fonctions":{"composition de fonctions":{"internalLink":{"count":1,"lastUpdated":1711904385231}}},"fonction":{"fonction":{"internalLink":{"count":2,"lastUpdated":1711904857369}}},"fonction pure":{"fonction pure":{"internalLink":{"count":1,"lastUpdated":1711915488076}}},"effets de bord":{"effets de bord":{"internalLink":{"count":1,"lastUpdated":1711915498637}}},"Alan Perlis":{"Alan Perlis":{"internalLink":{"count":1,"lastUpdated":1711915724379}}},"fonction racine carrée":{"fonction racine carrée":{"internalLink":{"count":1,"lastUpdated":1711916013705}}},"méthode de Newton":{"méthode de Newton":{"internalLink":{"count":1,"lastUpdated":1711916030171}}},"langages formels":{"langages formels":{"internalLink":{"count":1,"lastUpdated":1711916816989}}},"logique":{"logique":{"internalLink":{"count":1,"lastUpdated":1711916822650}}},"sophisme":{"sophisme":{"internalLink":{"count":1,"lastUpdated":1711916957089}}}}
{"matrice hessienne":{"matrice hessienne":{"internalLink":{"count":2,"lastUpdated":1710324879177}}},"manim Ellipse":{"manim Ellipse":{"internalLink":{"count":1,"lastUpdated":1709296590359}}},"baptême":{"baptême":{"internalLink":{"count":5,"lastUpdated":1709864270370}}},"gradient":{"gradient":{"internalLink":{"count":1,"lastUpdated":1710325461961}}},"obsidian plugin tag and wordcloud":{"obsidian plugin tag and wordcloud":{"internalLink":{"count":1,"lastUpdated":1710345237714}}},"intersection de sous groupes":{"intersection de sous groupes":{"internalLink":{"count":1,"lastUpdated":1710465530327}}},"valeurs":{"valeurs":{"internalLink":{"count":1,"lastUpdated":1711459246780}}},"Learning APL":{"Learning APL":{"internalLink":{"count":1,"lastUpdated":1711584419388}}},"structure de donnés":{"structure de donnés":{"internalLink":{"count":1,"lastUpdated":1711621251914}}},"paramètre":{"paramètre":{"internalLink":{"count":1,"lastUpdated":1711621492446}}},"langage de programmation":{"langage de programmation":{"internalLink":{"count":4,"lastUpdated":1711920773085}},"langage":{"internalLink":{"count":1,"lastUpdated":1711920903060}}},"argument d'une fonction":{"argument d'une fonction":{"internalLink":{"count":1,"lastUpdated":1711624010397}}},"argument":{"argument":{"internalLink":{"count":2,"lastUpdated":1711624133731}}},"techniques de pkm":{"techniques de pkm":{"internalLink":{"count":1,"lastUpdated":1711627281333}}},"paradigme de programmation":{"paradigme de programmation":{"internalLink":{"count":6,"lastUpdated":1711917618071}}},"état":{"état":{"internalLink":{"count":3,"lastUpdated":1711905774038}}},"structure de données":{"structure de données":{"internalLink":{"count":1,"lastUpdated":1711643699590}}},"structures de données":{"structures de données":{"internalLink":{"count":2,"lastUpdated":1711904665130}}},"enregistrement":{"enregistrement":{"internalLink":{"count":1,"lastUpdated":1711668283936}}},"envoi de messages entre objets":{"envoi de messages entre objets":{"internalLink":{"count":1,"lastUpdated":1711742931869}}},"programmation structurée":{"programmation structurée":{"internalLink":{"count":1,"lastUpdated":1711764089506}}},"effet de bord":{"effet de bord":{"internalLink":{"count":2,"lastUpdated":1711906516742}}},"programmation impérative":{"programmation impérative":{"internalLink":{"count":3,"lastUpdated":1711915570179}}},"composition de fonctions":{"composition de fonctions":{"internalLink":{"count":1,"lastUpdated":1711904385231}}},"fonction":{"fonction":{"internalLink":{"count":2,"lastUpdated":1711904857369}}},"fonction pure":{"fonction pure":{"internalLink":{"count":1,"lastUpdated":1711915488076}}},"effets de bord":{"effets de bord":{"internalLink":{"count":1,"lastUpdated":1711915498637}}},"Alan Perlis":{"Alan Perlis":{"internalLink":{"count":1,"lastUpdated":1711915724379}}},"fonction racine carrée":{"fonction racine carrée":{"internalLink":{"count":1,"lastUpdated":1711916013705}}},"méthode de Newton":{"méthode de Newton":{"internalLink":{"count":1,"lastUpdated":1711916030171}}},"langages formels":{"langages formels":{"internalLink":{"count":1,"lastUpdated":1711916816989}}},"logique":{"logique":{"internalLink":{"count":1,"lastUpdated":1711916822650}}},"sophisme":{"sophisme":{"internalLink":{"count":1,"lastUpdated":1711916957089}}},"définition":{"définition":{"currentVault":{"count":1,"lastUpdated":1711920701861},"currentFile":{"count":1,"lastUpdated":1711920749062}}},"remplissage":{"remplissage":{"currentVault":{"count":1,"lastUpdated":1711920704851}}},"défini":{"défini":{"currentFile":{"count":1,"lastUpdated":1711920747172}}},"SE - organisation des données":{"SE - organisation des données":{"internalLink":{"count":1,"lastUpdated":1711920824428}}},"Frédéric Lordon":{"Frédéric Lordon":{"internalLink":{"count":1,"lastUpdated":1711942941375}}}}

View File

@@ -0,0 +1,5 @@
.theme-light, .theme-dark {
--popover-width: 650px;
--popover-height: 600px;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
{
"name": "Wikipedia",
"version": "2.0.3",
"minAppversion": "1.0.0",
"author": "Ha'ani Whitlock",
"authorUrl": "https://github.com/Bluemoondragon07"
}

1140
.obsidian/themes/Wikipedia/theme.css vendored Normal file

File diff suppressed because one or more lines are too long