@autumnsgrove/groveengine 0.4.11 → 0.4.12

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.
@@ -40,6 +40,7 @@
40
40
  let cursorLine = $state(1);
41
41
  let cursorCol = $state(1);
42
42
  let isUpdating = $state(false);
43
+ let isProgrammaticUpdate = $state(false); // Flag to skip oninput during toolbar operations
43
44
 
44
45
  // Image upload state
45
46
  let isDragging = $state(false);
@@ -185,7 +186,7 @@
185
186
 
186
187
  // Cursor position tracking
187
188
  function updateCursorPosition() {
188
- if (!textareaRef) return;
189
+ if (!textareaRef || isProgrammaticUpdate) return; // Skip during programmatic updates
189
190
  const pos = textareaRef.selectionStart;
190
191
  const textBefore = content.substring(0, pos);
191
192
  const lines = textBefore.split("\n");
@@ -326,31 +327,41 @@
326
327
  }
327
328
 
328
329
  // Text manipulation helpers
329
- function wrapSelection(before, after) {
330
+ async function wrapSelection(before, after) {
330
331
  if (!textareaRef || isUpdating) return;
331
332
  isUpdating = true;
333
+ isProgrammaticUpdate = true;
334
+
332
335
  const start = textareaRef.selectionStart;
333
336
  const end = textareaRef.selectionEnd;
334
337
  const selectedText = content.substring(start, end);
335
338
  content = content.substring(0, start) + before + selectedText + after + content.substring(end);
336
- setTimeout(() => {
337
- textareaRef.selectionStart = start + before.length;
338
- textareaRef.selectionEnd = end + before.length;
339
- textareaRef.focus();
340
- isUpdating = false;
341
- }, 0);
339
+
340
+ await tick(); // Wait for Svelte to update DOM
341
+
342
+ textareaRef.selectionStart = start + before.length;
343
+ textareaRef.selectionEnd = end + before.length;
344
+ textareaRef.focus();
345
+
346
+ isProgrammaticUpdate = false;
347
+ isUpdating = false;
342
348
  }
343
349
 
344
- function insertAtCursor(text) {
350
+ async function insertAtCursor(text) {
345
351
  if (!textareaRef || isUpdating) return;
346
352
  isUpdating = true;
353
+ isProgrammaticUpdate = true;
354
+
347
355
  const start = textareaRef.selectionStart;
348
356
  content = content.substring(0, start) + text + content.substring(start);
349
- setTimeout(() => {
350
- textareaRef.selectionStart = textareaRef.selectionEnd = start + text.length;
351
- textareaRef.focus();
352
- isUpdating = false;
353
- }, 0);
357
+
358
+ await tick(); // Wait for Svelte to update DOM
359
+
360
+ textareaRef.selectionStart = textareaRef.selectionEnd = start + text.length;
361
+ textareaRef.focus();
362
+
363
+ isProgrammaticUpdate = false;
364
+ isUpdating = false;
354
365
  }
355
366
 
356
367
  // Toolbar actions
@@ -366,19 +377,24 @@
366
377
  insertAtCursor("![alt text](image-url)");
367
378
  }
368
379
 
369
- function insertCodeBlock() {
380
+ async function insertCodeBlock() {
370
381
  if (!textareaRef || isUpdating) return;
371
382
  isUpdating = true;
383
+ isProgrammaticUpdate = true;
384
+
372
385
  const start = textareaRef.selectionStart;
373
386
  const end = textareaRef.selectionEnd;
374
387
  const selectedText = content.substring(start, end);
375
388
  const codeBlock = "```\n" + (selectedText || "code here") + "\n```";
376
389
  content = content.substring(0, start) + codeBlock + content.substring(end);
377
- setTimeout(() => {
378
- textareaRef.selectionStart = textareaRef.selectionEnd = start + codeBlock.length;
379
- textareaRef.focus();
380
- isUpdating = false;
381
- }, 0);
390
+
391
+ await tick(); // Wait for Svelte to update DOM
392
+
393
+ textareaRef.selectionStart = textareaRef.selectionEnd = start + codeBlock.length;
394
+ textareaRef.focus();
395
+
396
+ isProgrammaticUpdate = false;
397
+ isUpdating = false;
382
398
  }
383
399
 
384
400
  function insertList() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autumnsgrove/groveengine",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "Multi-tenant blog engine for Grove Platform. Features gutter annotations, markdown editing, magic code auth, and Cloudflare Workers deployment.",
5
5
  "author": "AutumnsGrove",
6
6
  "license": "MIT",