@typbase/codemirror 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +15 -10
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1624,8 +1624,9 @@ const SCROLLBAR_ALLOWANCE = 12;
1624
1624
  function editorRenderWidth(scrollDOM, contentDOM) {
1625
1625
  const pane = scrollDOM.getBoundingClientRect();
1626
1626
  const gutters = scrollDOM.querySelector(".cm-gutters");
1627
- const style = getComputedStyle(contentDOM);
1628
- return Math.max(0, pane.width - (gutters?.getBoundingClientRect().width ?? 0) - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight) - SCROLLBAR_ALLOWANCE);
1627
+ const contentStyle = getComputedStyle(contentDOM);
1628
+ const scrollStyle = getComputedStyle(scrollDOM);
1629
+ return Math.max(0, pane.width - (gutters?.getBoundingClientRect().width ?? 0) - parseFloat(contentStyle.paddingLeft) - parseFloat(contentStyle.paddingRight) - parseFloat(scrollStyle.paddingLeft) - parseFloat(scrollStyle.paddingRight) - SCROLLBAR_ALLOWANCE);
1629
1630
  }
1630
1631
  const tooltipsStateEffect = StateEffect.define();
1631
1632
  const tooltipsStateField = StateField.define({
@@ -1981,16 +1982,20 @@ const tooltipViewPlugin = () => ViewPlugin.define((view) => ({ update(update) {
1981
1982
  view.dispatch({ effects: tooltipStateEffect.of(tooltip) });
1982
1983
  });
1983
1984
  } }));
1985
+ //#endregion
1986
+ //#region src/plugin.ts
1987
+ const bracketPairs = {
1988
+ "(": ")",
1989
+ "[": "]",
1990
+ "{": "}",
1991
+ $: "$"
1992
+ };
1984
1993
  const typstEditingExtensions = [EditorView.inputHandler.of((view, from, to, text) => {
1985
1994
  if (text !== " " || from !== to) return false;
1986
1995
  const { state } = view;
1987
- const pos = from;
1988
- const bracketPairs = {
1989
- "(": ")",
1990
- "[": "]",
1991
- "{": "}",
1992
- $: "$"
1993
- };
1996
+ const { main } = state.selection;
1997
+ if (!main.empty) return false;
1998
+ const pos = main.head;
1994
1999
  const before = state.doc.sliceString(pos - 1, pos);
1995
2000
  const after = state.doc.sliceString(pos, pos + 1);
1996
2001
  if (!bracketPairs[before] || after !== bracketPairs[before]) return false;
@@ -1998,7 +2003,7 @@ const typstEditingExtensions = [EditorView.inputHandler.of((view, from, to, text
1998
2003
  changes: {
1999
2004
  from: pos,
2000
2005
  to: pos,
2001
- insert: " "
2006
+ insert: " "
2002
2007
  },
2003
2008
  selection: { anchor: pos + 1 }
2004
2009
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typbase/codemirror",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "CodeMirror 6 editing experience for Typst: WYSIWYG inline preview, highlighting, hover, autocomplete.",
5
5
  "keywords": [
6
6
  "atproto",
@@ -40,7 +40,7 @@
40
40
  "typescript": "^5.9.3"
41
41
  },
42
42
  "peerDependencies": {
43
- "@typbase/engine": "^0.4.1"
43
+ "@typbase/engine": "^0.4.3"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsdown",