mirror of
https://github.com/heyman/heynote.git
synced 2025-06-28 13:31:38 +02:00
Add transactionsHasAnnotation utility function
This commit is contained in:
parent
c397511bda
commit
4e5a1139d9
@ -9,3 +9,9 @@ export const DELETE_BLOCK = "heynote-delete-block"
|
|||||||
export const CURSOR_CHANGE = "heynote-cursor-change"
|
export const CURSOR_CHANGE = "heynote-cursor-change"
|
||||||
export const APPEND_BLOCK = "heynote-append-block"
|
export const APPEND_BLOCK = "heynote-append-block"
|
||||||
export const SET_FONT = "heynote-set-font"
|
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)
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { RangeSetBuilder } from "@codemirror/state"
|
|||||||
import { WidgetType } from "@codemirror/view"
|
import { WidgetType } from "@codemirror/view"
|
||||||
|
|
||||||
import { getNoteBlockFromPos } from "./block"
|
import { getNoteBlockFromPos } from "./block"
|
||||||
import { CURRENCIES_LOADED } from "../annotation"
|
import { transactionsHasAnnotation, CURRENCIES_LOADED } from "../annotation"
|
||||||
|
|
||||||
|
|
||||||
class MathResult extends WidgetType {
|
class MathResult extends WidgetType {
|
||||||
@ -107,12 +107,6 @@ function mathDeco(view) {
|
|||||||
return builder.finish()
|
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 {
|
export const mathBlock = ViewPlugin.fromClass(class {
|
||||||
decorations
|
decorations
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { WidgetType } from "@codemirror/view"
|
|||||||
import { ViewUpdate, ViewPlugin, DecorationSet } from "@codemirror/view"
|
import { ViewUpdate, ViewPlugin, DecorationSet } from "@codemirror/view"
|
||||||
|
|
||||||
import { isMonospaceFont } from "./theme/font-theme"
|
import { isMonospaceFont } from "./theme/font-theme"
|
||||||
import { SET_FONT } from "./annotation"
|
import { transactionsHasAnnotation, SET_FONT } from "./annotation"
|
||||||
|
|
||||||
|
|
||||||
class CheckboxWidget extends WidgetType {
|
class CheckboxWidget extends WidgetType {
|
||||||
@ -111,7 +111,7 @@ export const todoCheckboxPlugin = [
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(update: ViewUpdate) {
|
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)
|
this.decorations = checkboxes(update.view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user