diff --git a/src/editor/annotation.js b/src/editor/annotation.js index 09342c2..5e46be7 100644 --- a/src/editor/annotation.js +++ b/src/editor/annotation.js @@ -9,3 +9,9 @@ export const DELETE_BLOCK = "heynote-delete-block" export const CURSOR_CHANGE = "heynote-cursor-change" export const APPEND_BLOCK = "heynote-append-block" export const SET_FONT = "heynote-set-font" + + +// This function checks if any of the transactions has the given Heynote annotation +export function transactionsHasAnnotation(transactions, annotation) { + return transactions.some(tr => tr.annotation(heynoteEvent) === annotation) +} diff --git a/src/editor/block/math.js b/src/editor/block/math.js index b76a73f..4de7061 100644 --- a/src/editor/block/math.js +++ b/src/editor/block/math.js @@ -4,7 +4,7 @@ import { RangeSetBuilder } from "@codemirror/state" import { WidgetType } from "@codemirror/view" import { getNoteBlockFromPos } from "./block" -import { CURRENCIES_LOADED } from "../annotation" +import { transactionsHasAnnotation, CURRENCIES_LOADED } from "../annotation" class MathResult extends WidgetType { @@ -107,12 +107,6 @@ function mathDeco(view) { return builder.finish() } - -// This function checks if any of the transactions has the given annotation -const transactionsHasAnnotation = (transactions, annotation) => { - return transactions.some(tr => tr.annotations.some(a => a.value === annotation)) -} - export const mathBlock = ViewPlugin.fromClass(class { decorations diff --git a/src/editor/todo-checkbox.ts b/src/editor/todo-checkbox.ts index 60d76a6..a25a1ee 100644 --- a/src/editor/todo-checkbox.ts +++ b/src/editor/todo-checkbox.ts @@ -4,7 +4,7 @@ import { WidgetType } from "@codemirror/view" import { ViewUpdate, ViewPlugin, DecorationSet } from "@codemirror/view" import { isMonospaceFont } from "./theme/font-theme" -import { SET_FONT } from "./annotation" +import { transactionsHasAnnotation, SET_FONT } from "./annotation" class CheckboxWidget extends WidgetType { @@ -111,7 +111,7 @@ export const todoCheckboxPlugin = [ } update(update: ViewUpdate) { - if (update.docChanged || update.viewportChanged || update.transactions.some(tr => tr.annotations.some(a => a.value === SET_FONT))) { + if (update.docChanged || update.viewportChanged || transactionsHasAnnotation(update.transactions, SET_FONT)) { this.decorations = checkboxes(update.view) } }