Add transactionsHasAnnotation utility function

This commit is contained in:
Jonatan Heyman 2025-04-07 13:34:03 +02:00
parent c397511bda
commit 4e5a1139d9
3 changed files with 9 additions and 9 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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)
}
}