MCPcopy
hub / github.com/callumalpass/tasknotes / createInstantConvertField

Function createInstantConvertField

src/editor/InstantConvertButtons.ts:200–232  ·  view source on GitHub ↗
(plugin: TaskNotesPlugin)

Source from the content-addressed store, hash-verified

198}
199
200export function createInstantConvertField(plugin: TaskNotesPlugin) {
201 return ViewPlugin.fromClass(
202 class implements PluginValue {
203 decorations: DecorationSet;
204 private enabled: boolean;
205
206 constructor(view: EditorView) {
207 this.enabled = Boolean(plugin?.settings?.enableInstantTaskConvert);
208 this.decorations = this.enabled
209 ? buildConvertButtonDecorations(view, plugin)
210 : Decoration.none;
211 }
212
213 update(update: ViewUpdate): void {
214 const enabled = Boolean(plugin?.settings?.enableInstantTaskConvert);
215
216 if (!enabled) {
217 this.enabled = false;
218 this.decorations = Decoration.none;
219 return;
220 }
221
222 if (!this.enabled || update.docChanged || update.viewportChanged) {
223 this.enabled = true;
224 this.decorations = buildConvertButtonDecorations(update.view, plugin);
225 }
226 }
227 },
228 {
229 decorations: (value) => value.decorations,
230 }
231 );
232}
233
234type ConvertButtonDocument = {
235 lines: number;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected