weml-monaco 0.7.0 → 0.7.1

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.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,13 @@ This package shares the language logic of the VS Code extension (`weml-support`)
8
8
  entries below track the port catching up with its provider changes; since the shared language
9
9
  features, both take the same code.
10
10
 
11
+ ## [0.7.1] — 2026-10-09
12
+
13
+ ### Fixed
14
+ - Cycle formatting restores each cursor to its containing `div` by ID, or to
15
+ the closest `div` on the same line or nearby lines when outside a block.
16
+ The block selection logic is shared with the VS Code extension.
17
+
11
18
  ## [0.7.0] — 2026-10-08
12
19
 
13
20
  ### Added
package/dist/index.cjs CHANGED
@@ -31678,6 +31678,47 @@ function planDivIdRenumber(text) {
31678
31678
  return edits;
31679
31679
  }
31680
31680
 
31681
+ // ../weml-language-core/src/toolbar/formatCursor.ts
31682
+ function collectDivs2(nodes, divs = []) {
31683
+ for (const node of nodes) {
31684
+ if (node.tag?.toLowerCase() === "div") divs.push(node);
31685
+ collectDivs2(node.children, divs);
31686
+ }
31687
+ return divs;
31688
+ }
31689
+ function uniqueDivWithId(divs, id) {
31690
+ const matches = divs.filter((node) => stripQuotes2(node.attributes?.id) === id);
31691
+ return matches.length === 1 ? matches[0] : void 0;
31692
+ }
31693
+ function formatCursorDivId(textDocument, htmlDocument, offset) {
31694
+ const divs = collectDivs2(htmlDocument.roots);
31695
+ let selected;
31696
+ for (const div of divs) {
31697
+ if (div.start <= offset && offset < div.end) selected = div;
31698
+ }
31699
+ if (!selected) {
31700
+ const line = textDocument.positionAt(offset).line;
31701
+ let bestLineDistance = Infinity;
31702
+ let bestOffsetDistance = Infinity;
31703
+ for (const div of divs) {
31704
+ const startLine = textDocument.positionAt(div.start).line;
31705
+ const endLine = textDocument.positionAt(Math.max(div.start, div.end - 1)).line;
31706
+ const lineDistance = Math.max(startLine - line, line - endLine, 0);
31707
+ const offsetDistance = Math.max(div.start - offset, offset - div.end, 0);
31708
+ if (lineDistance < bestLineDistance || lineDistance === bestLineDistance && offsetDistance < bestOffsetDistance) {
31709
+ selected = div;
31710
+ bestLineDistance = lineDistance;
31711
+ bestOffsetDistance = offsetDistance;
31712
+ }
31713
+ }
31714
+ }
31715
+ const id = stripQuotes2(selected?.attributes?.id);
31716
+ return id && uniqueDivWithId(divs, id) ? id : void 0;
31717
+ }
31718
+ function formatCursorDivOffset(htmlDocument, id) {
31719
+ return uniqueDivWithId(collectDivs2(htmlDocument.roots), id)?.start;
31720
+ }
31721
+
31681
31722
  // ../weml-language-core/src/toolbar/toolModel.ts
31682
31723
  var WRAP_INLINE_TAGS = ["w-color", "w-lang", "w-non-egw", "w-entity", "w-sent", "a"];
31683
31724
  var WRAP_OPTIONS = [
@@ -32247,7 +32288,32 @@ function cycleFormat(editor, options = {}) {
32247
32288
  cycleState.set(key, step + 1);
32248
32289
  options.onStatus?.(asHtml ? "WEML: formatted as HTML" : "WEML: canonical format");
32249
32290
  if (formatted === original) return;
32250
- editor.executeEdits("weml.cycleFormat", [{ range: model.getFullModelRange(), text: formatted }]);
32291
+ const { textDocument, htmlDocument } = getWemlDocument(model);
32292
+ const divIds = (editor.getSelections() ?? []).map((selection) => selection.isEmpty() ? formatCursorDivId(textDocument, htmlDocument, offsetAt(textDocument, selection.getPosition())) : void 0);
32293
+ const applied = editor.executeEdits("weml.cycleFormat", [{ range: model.getFullModelRange(), text: formatted }]);
32294
+ if (!applied || !divIds.some((id) => id !== void 0) || editor.getModel() !== model) return;
32295
+ const selections = editor.getSelections();
32296
+ if (!selections || selections.length !== divIds.length) return;
32297
+ const updated = getWemlDocument(model);
32298
+ let primaryPosition;
32299
+ editor.setSelections(selections.map((selection, index) => {
32300
+ const id = divIds[index];
32301
+ const offset = id === void 0 ? void 0 : formatCursorDivOffset(updated.htmlDocument, id);
32302
+ if (offset === void 0) return selection;
32303
+ const position = positionAt(updated.textDocument, offset);
32304
+ if (index === 0) primaryPosition = position;
32305
+ return {
32306
+ startLineNumber: position.lineNumber,
32307
+ startColumn: position.column,
32308
+ endLineNumber: position.lineNumber,
32309
+ endColumn: position.column,
32310
+ selectionStartLineNumber: position.lineNumber,
32311
+ selectionStartColumn: position.column,
32312
+ positionLineNumber: position.lineNumber,
32313
+ positionColumn: position.column
32314
+ };
32315
+ }), "weml.cycleFormat");
32316
+ if (primaryPosition) editor.revealPositionInCenterIfOutsideViewport(primaryPosition);
32251
32317
  }
32252
32318
  function registerWemlEditorActions(m2, editor, options = {}) {
32253
32319
  const disposables = [];