@opentui/core 0.1.29 → 0.1.31

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/index.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  DataPathsManager,
11
11
  DebugOverlayCorner,
12
12
  Edge,
13
+ ExtmarksController,
13
14
  Gutter,
14
15
  InternalKeyHandler,
15
16
  KeyEvent,
@@ -62,6 +63,7 @@ import {
62
63
  convertGlobalToLocalSelection,
63
64
  coordinateToCharacterIndex,
64
65
  createCliRenderer,
66
+ createExtmarksController,
65
67
  createTextAttributes,
66
68
  cyan,
67
69
  delegate,
@@ -131,7 +133,7 @@ import {
131
133
  white,
132
134
  wrapWithDelegates,
133
135
  yellow
134
- } from "./index-bztetjc3.js";
136
+ } from "./index-91qheh74.js";
135
137
  // src/text-buffer-view.ts
136
138
  class TextBufferView {
137
139
  lib;
@@ -329,6 +331,10 @@ class EditBuffer extends EventEmitter {
329
331
  this.guard();
330
332
  this.lib.editBufferDeleteCharBackward(this.bufferPtr);
331
333
  }
334
+ deleteRange(startLine, startCol, endLine, endCol) {
335
+ this.guard();
336
+ this.lib.editBufferDeleteRange(this.bufferPtr, startLine, startCol, endLine, endCol);
337
+ }
332
338
  newLine() {
333
339
  this.guard();
334
340
  this.lib.editBufferNewLine(this.bufferPtr);
@@ -373,6 +379,48 @@ class EditBuffer extends EventEmitter {
373
379
  this.guard();
374
380
  return this.lib.editBufferGetCursorPosition(this.bufferPtr);
375
381
  }
382
+ getNextWordBoundary() {
383
+ this.guard();
384
+ const boundary = this.lib.editBufferGetNextWordBoundary(this.bufferPtr);
385
+ return {
386
+ row: boundary.row,
387
+ col: boundary.col,
388
+ offset: boundary.offset
389
+ };
390
+ }
391
+ getPrevWordBoundary() {
392
+ this.guard();
393
+ const boundary = this.lib.editBufferGetPrevWordBoundary(this.bufferPtr);
394
+ return {
395
+ row: boundary.row,
396
+ col: boundary.col,
397
+ offset: boundary.offset
398
+ };
399
+ }
400
+ getEOL() {
401
+ this.guard();
402
+ const boundary = this.lib.editBufferGetEOL(this.bufferPtr);
403
+ return {
404
+ row: boundary.row,
405
+ col: boundary.col,
406
+ offset: boundary.offset
407
+ };
408
+ }
409
+ offsetToPosition(offset) {
410
+ this.guard();
411
+ const result = this.lib.editBufferOffsetToPosition(this.bufferPtr, offset);
412
+ if (!result)
413
+ return null;
414
+ return { row: result.row, col: result.col };
415
+ }
416
+ positionToOffset(row, col) {
417
+ this.guard();
418
+ return this.lib.editBufferPositionToOffset(this.bufferPtr, row, col);
419
+ }
420
+ getLineStartOffset(row) {
421
+ this.guard();
422
+ return this.lib.editBufferGetLineStartOffset(this.bufferPtr, row);
423
+ }
376
424
  debugLogRope() {
377
425
  this.guard();
378
426
  this.lib.editBufferDebugLogRope(this.bufferPtr);
@@ -421,14 +469,6 @@ class EditBuffer extends EventEmitter {
421
469
  this.guard();
422
470
  this.lib.textBufferResetDefaults(this.textBufferPtr);
423
471
  }
424
- setPlaceholder(text) {
425
- this.guard();
426
- this.lib.editBufferSetPlaceholder(this.bufferPtr, text);
427
- }
428
- setPlaceholderColor(color) {
429
- this.guard();
430
- this.lib.editBufferSetPlaceholderColor(this.bufferPtr, color);
431
- }
432
472
  setSyntaxStyle(style) {
433
473
  this.guard();
434
474
  this._syntaxStyle = style ?? undefined;
@@ -462,6 +502,10 @@ class EditBuffer extends EventEmitter {
462
502
  this.guard();
463
503
  return this.lib.textBufferGetLineHighlights(this.textBufferPtr, lineIdx);
464
504
  }
505
+ clear() {
506
+ this.guard();
507
+ this.lib.editBufferClear(this.bufferPtr);
508
+ }
465
509
  destroy() {
466
510
  if (this._destroyed)
467
511
  return;
@@ -476,6 +520,7 @@ class EditorView {
476
520
  viewPtr;
477
521
  editBuffer;
478
522
  _destroyed = false;
523
+ _extmarksController;
479
524
  constructor(lib, ptr, editBuffer) {
480
525
  this.lib = lib;
481
526
  this.viewPtr = ptr;
@@ -582,19 +627,43 @@ class EditorView {
582
627
  this.guard();
583
628
  this.lib.editorViewSetCursorByOffset(this.viewPtr, offset);
584
629
  }
630
+ getNextWordBoundary() {
631
+ this.guard();
632
+ return this.lib.editorViewGetNextWordBoundary(this.viewPtr);
633
+ }
634
+ getPrevWordBoundary() {
635
+ this.guard();
636
+ return this.lib.editorViewGetPrevWordBoundary(this.viewPtr);
637
+ }
638
+ getEOL() {
639
+ this.guard();
640
+ return this.lib.editorViewGetEOL(this.viewPtr);
641
+ }
585
642
  getLineInfo() {
586
643
  this.guard();
587
- const textBufferViewPtr = this.lib.editorViewGetTextBufferView(this.viewPtr);
588
- return this.lib.textBufferViewGetLineInfo(textBufferViewPtr);
644
+ return this.lib.editorViewGetLineInfo(this.viewPtr);
589
645
  }
590
646
  getLogicalLineInfo() {
591
647
  this.guard();
592
- const textBufferViewPtr = this.lib.editorViewGetTextBufferView(this.viewPtr);
593
- return this.lib.textBufferViewGetLogicalLineInfo(textBufferViewPtr);
648
+ return this.lib.editorViewGetLogicalLineInfo(this.viewPtr);
649
+ }
650
+ get extmarks() {
651
+ if (!this._extmarksController) {
652
+ this._extmarksController = createExtmarksController(this.editBuffer, this);
653
+ }
654
+ return this._extmarksController;
655
+ }
656
+ setPlaceholderStyledText(chunks) {
657
+ this.guard();
658
+ this.lib.editorViewSetPlaceholderStyledText(this.viewPtr, chunks);
594
659
  }
595
660
  destroy() {
596
661
  if (this._destroyed)
597
662
  return;
663
+ if (this._extmarksController) {
664
+ this._extmarksController.destroy();
665
+ this._extmarksController = undefined;
666
+ }
598
667
  this._destroyed = true;
599
668
  this.lib.destroyEditorView(this.viewPtr);
600
669
  }
@@ -2429,8 +2498,9 @@ class TextBufferRenderable extends Renderable {
2429
2498
  }
2430
2499
  setupMeasureFunc() {
2431
2500
  const measureFunc = (width, widthMode, height, heightMode) => {
2432
- if (this._wrapMode !== "none" && this.width !== width) {
2433
- this.updateWrapWidth(width);
2501
+ const effectiveWidth = isNaN(width) ? 1 : width;
2502
+ if (this._wrapMode !== "none" && this.width !== effectiveWidth) {
2503
+ this.updateWrapWidth(effectiveWidth);
2434
2504
  } else {
2435
2505
  this.updateLineInfo();
2436
2506
  }
@@ -5004,8 +5074,8 @@ class EditBufferRenderable extends Renderable {
5004
5074
  if (this._cursorChangeListener) {
5005
5075
  const cursor = this.editBuffer.getCursorPosition();
5006
5076
  this._cursorChangeListener({
5007
- line: cursor.line,
5008
- visualColumn: cursor.visualColumn
5077
+ line: cursor.row,
5078
+ visualColumn: cursor.col
5009
5079
  });
5010
5080
  }
5011
5081
  });
@@ -5020,14 +5090,18 @@ class EditBufferRenderable extends Renderable {
5020
5090
  get plainText() {
5021
5091
  return this.editBuffer.getText();
5022
5092
  }
5023
- get cursor() {
5093
+ get logicalCursor() {
5024
5094
  return this.editBuffer.getCursorPosition();
5025
5095
  }
5026
5096
  get visualCursor() {
5027
5097
  return this.editorView.getVisualCursor();
5028
5098
  }
5099
+ get cursorOffset() {
5100
+ return this.editorView.getVisualCursor().offset;
5101
+ }
5029
5102
  set cursorOffset(offset) {
5030
5103
  this.editorView.setCursorByOffset(offset);
5104
+ this.requestRender();
5031
5105
  }
5032
5106
  get textColor() {
5033
5107
  return this._textColor;
@@ -5166,10 +5240,12 @@ class EditBufferRenderable extends Renderable {
5166
5240
  }
5167
5241
  setupMeasureFunc() {
5168
5242
  const measureFunc = (width, widthMode, height, heightMode) => {
5169
- if (this._wrapMode !== "none" && this.width !== width) {
5170
- this.editorView.setViewportSize(width, height);
5243
+ const effectiveHeight = isNaN(height) ? 1 : height;
5244
+ const effectiveWidth = isNaN(width) ? 1 : width;
5245
+ if (this._wrapMode !== "none" && this.width !== effectiveWidth) {
5246
+ this.editorView.setViewportSize(effectiveWidth, effectiveHeight);
5171
5247
  } else {
5172
- this.editorView.setViewportSize(width, height);
5248
+ this.editorView.setViewportSize(effectiveWidth, effectiveHeight);
5173
5249
  }
5174
5250
  const lineInfo = this.editorView.getLogicalLineInfo();
5175
5251
  const measuredWidth = lineInfo.maxLineWidth;
@@ -5247,24 +5323,133 @@ class EditBufferRenderable extends Renderable {
5247
5323
  this.editBuffer.setSyntaxStyle(style);
5248
5324
  this.requestRender();
5249
5325
  }
5326
+ addHighlight(lineIdx, highlight) {
5327
+ this.editBuffer.addHighlight(lineIdx, highlight);
5328
+ this.requestRender();
5329
+ }
5330
+ addHighlightByCharRange(highlight) {
5331
+ this.editBuffer.addHighlightByCharRange(highlight);
5332
+ this.requestRender();
5333
+ }
5334
+ removeHighlightsByRef(hlRef) {
5335
+ this.editBuffer.removeHighlightsByRef(hlRef);
5336
+ this.requestRender();
5337
+ }
5338
+ clearLineHighlights(lineIdx) {
5339
+ this.editBuffer.clearLineHighlights(lineIdx);
5340
+ this.requestRender();
5341
+ }
5342
+ clearAllHighlights() {
5343
+ this.editBuffer.clearAllHighlights();
5344
+ this.requestRender();
5345
+ }
5346
+ getLineHighlights(lineIdx) {
5347
+ return this.editBuffer.getLineHighlights(lineIdx);
5348
+ }
5349
+ setText(text, opts) {
5350
+ this.editBuffer.setText(text, opts);
5351
+ this.yogaNode.markDirty();
5352
+ this.requestRender();
5353
+ }
5354
+ clear() {
5355
+ this.editBuffer.clear();
5356
+ this.editBuffer.clearAllHighlights();
5357
+ this.yogaNode.markDirty();
5358
+ this.requestRender();
5359
+ }
5360
+ deleteRange(startLine, startCol, endLine, endCol) {
5361
+ this.editBuffer.deleteRange(startLine, startCol, endLine, endCol);
5362
+ this.yogaNode.markDirty();
5363
+ this.requestRender();
5364
+ }
5365
+ insertText(text) {
5366
+ this.editBuffer.insertText(text);
5367
+ this.yogaNode.markDirty();
5368
+ this.requestRender();
5369
+ }
5370
+ }
5371
+
5372
+ // src/lib/keymapping.ts
5373
+ function mergeKeyBindings(defaults, custom) {
5374
+ const map = new Map;
5375
+ for (const binding of defaults) {
5376
+ const key = getKeyBindingKey(binding);
5377
+ map.set(key, binding);
5378
+ }
5379
+ for (const binding of custom) {
5380
+ const key = getKeyBindingKey(binding);
5381
+ map.set(key, binding);
5382
+ }
5383
+ return Array.from(map.values());
5384
+ }
5385
+ function getKeyBindingKey(binding) {
5386
+ return `${binding.name}:${!!binding.ctrl}:${!!binding.shift}:${!!binding.meta}`;
5387
+ }
5388
+ function buildKeyBindingsMap(bindings) {
5389
+ const map = new Map;
5390
+ for (const binding of bindings) {
5391
+ const key = getKeyBindingKey(binding);
5392
+ map.set(key, binding.action);
5393
+ }
5394
+ return map;
5250
5395
  }
5251
5396
 
5252
5397
  // src/renderables/Textarea.ts
5398
+ var defaultTextareaKeybindings = [
5399
+ { name: "left", action: "move-left" },
5400
+ { name: "right", action: "move-right" },
5401
+ { name: "up", action: "move-up" },
5402
+ { name: "down", action: "move-down" },
5403
+ { name: "left", shift: true, action: "select-left" },
5404
+ { name: "right", shift: true, action: "select-right" },
5405
+ { name: "up", shift: true, action: "select-up" },
5406
+ { name: "down", shift: true, action: "select-down" },
5407
+ { name: "home", action: "line-home" },
5408
+ { name: "end", action: "line-end" },
5409
+ { name: "home", shift: true, action: "select-line-home" },
5410
+ { name: "end", shift: true, action: "select-line-end" },
5411
+ { name: "a", ctrl: true, action: "buffer-home" },
5412
+ { name: "e", ctrl: true, action: "buffer-end" },
5413
+ { name: "d", ctrl: true, action: "delete-line" },
5414
+ { name: "k", ctrl: true, action: "delete-to-line-end" },
5415
+ { name: "backspace", action: "backspace" },
5416
+ { name: "delete", action: "delete" },
5417
+ { name: "return", action: "newline" },
5418
+ { name: "enter", action: "newline" },
5419
+ { name: "return", meta: true, action: "submit" },
5420
+ { name: "enter", meta: true, action: "submit" },
5421
+ { name: "z", ctrl: true, action: "undo" },
5422
+ { name: "Z", ctrl: true, shift: true, action: "redo" },
5423
+ { name: "y", ctrl: true, action: "redo" },
5424
+ { name: "f", meta: true, action: "word-forward" },
5425
+ { name: "b", meta: true, action: "word-backward" },
5426
+ { name: "right", meta: true, action: "word-forward" },
5427
+ { name: "left", meta: true, action: "word-backward" },
5428
+ { name: "F", meta: true, shift: true, action: "select-word-forward" },
5429
+ { name: "B", meta: true, shift: true, action: "select-word-backward" },
5430
+ { name: "right", meta: true, shift: true, action: "select-word-forward" },
5431
+ { name: "left", meta: true, shift: true, action: "select-word-backward" },
5432
+ { name: "d", meta: true, action: "delete-word-forward" },
5433
+ { name: "backspace", meta: true, action: "delete-word-backward" },
5434
+ { name: "w", ctrl: true, action: "delete-word-backward" }
5435
+ ];
5436
+
5253
5437
  class TextareaRenderable extends EditBufferRenderable {
5254
5438
  _placeholder;
5255
5439
  _unfocusedBackgroundColor;
5256
5440
  _unfocusedTextColor;
5257
5441
  _focusedBackgroundColor;
5258
5442
  _focusedTextColor;
5259
- _placeholderColor;
5443
+ _keyBindingsMap;
5444
+ _actionHandlers;
5445
+ _initialValueSet = false;
5446
+ _submitListener = undefined;
5260
5447
  static defaults = {
5261
- value: "",
5262
5448
  backgroundColor: "transparent",
5263
5449
  textColor: "#FFFFFF",
5264
5450
  focusedBackgroundColor: "transparent",
5265
5451
  focusedTextColor: "#FFFFFF",
5266
- placeholder: null,
5267
- placeholderColor: "#666666"
5452
+ placeholder: null
5268
5453
  };
5269
5454
  constructor(ctx, options) {
5270
5455
  const defaults = TextareaRenderable.defaults;
@@ -5279,14 +5464,64 @@ class TextareaRenderable extends EditBufferRenderable {
5279
5464
  this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || defaults.focusedBackgroundColor);
5280
5465
  this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || defaults.focusedTextColor);
5281
5466
  this._placeholder = options.placeholder ?? defaults.placeholder;
5282
- this._placeholderColor = parseColor(options.placeholderColor || defaults.placeholderColor);
5283
- this.updateValue(options.value ?? defaults.value);
5467
+ const mergedBindings = mergeKeyBindings(defaultTextareaKeybindings, options.keyBindings || []);
5468
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings);
5469
+ this._actionHandlers = this.buildActionHandlers();
5470
+ this._submitListener = options.onSubmit;
5471
+ if (options.initialValue) {
5472
+ this.setText(options.initialValue);
5473
+ this._initialValueSet = true;
5474
+ }
5284
5475
  this.updateColors();
5285
- this.editBuffer.setPlaceholder(this._placeholder);
5286
- this.editBuffer.setPlaceholderColor(this._placeholderColor);
5476
+ this.applyPlaceholder(this._placeholder);
5287
5477
  }
5288
- handlePaste(text) {
5289
- this.insertText(text);
5478
+ applyPlaceholder(placeholder) {
5479
+ if (placeholder === null) {
5480
+ this.editorView.setPlaceholderStyledText([]);
5481
+ return;
5482
+ }
5483
+ if (typeof placeholder === "string") {
5484
+ const defaultGray = fg("#666666");
5485
+ const chunks = [defaultGray(placeholder)];
5486
+ this.editorView.setPlaceholderStyledText(chunks);
5487
+ } else {
5488
+ this.editorView.setPlaceholderStyledText(placeholder.chunks);
5489
+ }
5490
+ }
5491
+ buildActionHandlers() {
5492
+ return new Map([
5493
+ ["move-left", () => this.moveCursorLeft()],
5494
+ ["move-right", () => this.moveCursorRight()],
5495
+ ["move-up", () => this.moveCursorUp()],
5496
+ ["move-down", () => this.moveCursorDown()],
5497
+ ["select-left", () => this.moveCursorLeft({ select: true })],
5498
+ ["select-right", () => this.moveCursorRight({ select: true })],
5499
+ ["select-up", () => this.moveCursorUp({ select: true })],
5500
+ ["select-down", () => this.moveCursorDown({ select: true })],
5501
+ ["line-home", () => this.gotoLineHome()],
5502
+ ["line-end", () => this.gotoLineEnd()],
5503
+ ["select-line-home", () => this.gotoLineHome({ select: true })],
5504
+ ["select-line-end", () => this.gotoLineEnd({ select: true })],
5505
+ ["buffer-home", () => this.gotoBufferHome()],
5506
+ ["buffer-end", () => this.gotoBufferEnd()],
5507
+ ["delete-line", () => this.deleteLine()],
5508
+ ["delete-to-line-end", () => this.deleteToLineEnd()],
5509
+ ["backspace", () => this.deleteCharBackward()],
5510
+ ["delete", () => this.deleteChar()],
5511
+ ["newline", () => this.newLine()],
5512
+ ["undo", () => this.undo()],
5513
+ ["redo", () => this.redo()],
5514
+ ["word-forward", () => this.moveWordForward()],
5515
+ ["word-backward", () => this.moveWordBackward()],
5516
+ ["select-word-forward", () => this.moveWordForward({ select: true })],
5517
+ ["select-word-backward", () => this.moveWordBackward({ select: true })],
5518
+ ["delete-word-forward", () => this.deleteWordForward()],
5519
+ ["delete-word-backward", () => this.deleteWordBackward()],
5520
+ ["submit", () => this.submit()]
5521
+ ]);
5522
+ }
5523
+ handlePaste(event) {
5524
+ this.insertText(event.text);
5290
5525
  }
5291
5526
  handleKeyPress(key) {
5292
5527
  const keyName = typeof key === "string" ? key : key.name;
@@ -5294,65 +5529,21 @@ class TextareaRenderable extends EditBufferRenderable {
5294
5529
  const keyCtrl = typeof key === "string" ? false : key.ctrl;
5295
5530
  const keyShift = typeof key === "string" ? false : key.shift;
5296
5531
  const keyMeta = typeof key === "string" ? false : key.meta;
5297
- if (keyCtrl && keyName === "z" && !keyShift) {
5298
- this.undo();
5299
- return true;
5300
- } else if (keyCtrl && keyName === "y" || keyCtrl && keyShift && keyName === "z") {
5301
- this.redo();
5302
- return true;
5303
- } else if (keyName === "left") {
5304
- this.handleShiftSelection(keyShift, true);
5305
- this.moveCursorLeft();
5306
- this.handleShiftSelection(keyShift, false);
5307
- return true;
5308
- } else if (keyName === "right") {
5309
- this.handleShiftSelection(keyShift, true);
5310
- this.moveCursorRight();
5311
- this.handleShiftSelection(keyShift, false);
5312
- return true;
5313
- } else if (keyName === "up") {
5314
- this.handleShiftSelection(keyShift, true);
5315
- this.moveCursorUp();
5316
- this.handleShiftSelection(keyShift, false);
5317
- return true;
5318
- } else if (keyName === "down") {
5319
- this.handleShiftSelection(keyShift, true);
5320
- this.moveCursorDown();
5321
- this.handleShiftSelection(keyShift, false);
5322
- return true;
5323
- } else if (keyName === "home") {
5324
- this.handleShiftSelection(keyShift, true);
5325
- const cursor = this.editorView.getCursor();
5326
- this.editBuffer.setCursor(cursor.row, 0);
5327
- this.handleShiftSelection(keyShift, false);
5328
- return true;
5329
- } else if (keyName === "end") {
5330
- this.handleShiftSelection(keyShift, true);
5331
- this.gotoLineEnd();
5332
- this.handleShiftSelection(keyShift, false);
5333
- return true;
5334
- } else if (keyCtrl && keyName === "a") {
5335
- this.editBuffer.setCursor(0, 0);
5336
- return true;
5337
- } else if (keyCtrl && keyName === "e") {
5338
- this.gotoBufferEnd();
5339
- return true;
5340
- } else if (keyCtrl && keyName === "d") {
5341
- this.deleteLine();
5342
- return true;
5343
- } else if (keyCtrl && keyName === "k") {
5344
- this.deleteToLineEnd();
5345
- return true;
5346
- } else if (keyName === "backspace") {
5347
- this.deleteCharBackward();
5348
- return true;
5349
- } else if (keyName === "delete") {
5350
- this.deleteChar();
5351
- return true;
5352
- } else if (keyName === "return" || keyName === "enter") {
5353
- this.newLine();
5354
- return true;
5355
- } else if (keySequence && !keyCtrl && !keyMeta) {
5532
+ const bindingKey = getKeyBindingKey({
5533
+ name: keyName,
5534
+ ctrl: keyCtrl,
5535
+ shift: keyShift,
5536
+ meta: keyMeta,
5537
+ action: "move-left"
5538
+ });
5539
+ const action = this._keyBindingsMap.get(bindingKey);
5540
+ if (action) {
5541
+ const handler = this._actionHandlers.get(action);
5542
+ if (handler) {
5543
+ return handler();
5544
+ }
5545
+ }
5546
+ if (keySequence && !keyCtrl && !keyMeta) {
5356
5547
  const firstCharCode = keySequence.charCodeAt(0);
5357
5548
  if (firstCharCode < 32) {
5358
5549
  return false;
@@ -5365,17 +5556,6 @@ class TextareaRenderable extends EditBufferRenderable {
5365
5556
  }
5366
5557
  return false;
5367
5558
  }
5368
- get value() {
5369
- return this.editBuffer.getText();
5370
- }
5371
- set value(value) {
5372
- this.updateValue(value);
5373
- }
5374
- updateValue(value) {
5375
- this.editBuffer.setText(value, { history: false });
5376
- this.yogaNode.markDirty();
5377
- this.requestRender();
5378
- }
5379
5559
  updateColors() {
5380
5560
  const effectiveBg = this._focused ? this._focusedBackgroundColor : this._unfocusedBackgroundColor;
5381
5561
  const effectiveFg = this._focused ? this._focusedTextColor : this._unfocusedTextColor;
@@ -5399,20 +5579,22 @@ class TextareaRenderable extends EditBufferRenderable {
5399
5579
  deleteChar() {
5400
5580
  if (this.hasSelection()) {
5401
5581
  this.deleteSelectedText();
5402
- return;
5582
+ return true;
5403
5583
  }
5404
5584
  this._ctx.clearSelection();
5405
5585
  this.editBuffer.deleteChar();
5406
5586
  this.requestRender();
5587
+ return true;
5407
5588
  }
5408
5589
  deleteCharBackward() {
5409
5590
  if (this.hasSelection()) {
5410
5591
  this.deleteSelectedText();
5411
- return;
5592
+ return true;
5412
5593
  }
5413
5594
  this._ctx.clearSelection();
5414
5595
  this.editBuffer.deleteCharBackward();
5415
5596
  this.requestRender();
5597
+ return true;
5416
5598
  }
5417
5599
  deleteSelectedText() {
5418
5600
  this.editorView.deleteSelectedText();
@@ -5423,69 +5605,144 @@ class TextareaRenderable extends EditBufferRenderable {
5423
5605
  this._ctx.clearSelection();
5424
5606
  this.editBuffer.newLine();
5425
5607
  this.requestRender();
5608
+ return true;
5426
5609
  }
5427
5610
  deleteLine() {
5428
5611
  this._ctx.clearSelection();
5429
5612
  this.editBuffer.deleteLine();
5430
5613
  this.requestRender();
5614
+ return true;
5431
5615
  }
5432
- moveCursorLeft() {
5616
+ moveCursorLeft(options) {
5617
+ const select = options?.select ?? false;
5618
+ this.handleShiftSelection(select, true);
5433
5619
  this.editBuffer.moveCursorLeft();
5620
+ this.handleShiftSelection(select, false);
5434
5621
  this.requestRender();
5622
+ return true;
5435
5623
  }
5436
- moveCursorRight() {
5624
+ moveCursorRight(options) {
5625
+ const select = options?.select ?? false;
5626
+ this.handleShiftSelection(select, true);
5437
5627
  this.editBuffer.moveCursorRight();
5628
+ this.handleShiftSelection(select, false);
5438
5629
  this.requestRender();
5630
+ return true;
5439
5631
  }
5440
- moveCursorUp() {
5632
+ moveCursorUp(options) {
5633
+ const select = options?.select ?? false;
5634
+ this.handleShiftSelection(select, true);
5441
5635
  this.editorView.moveUpVisual();
5636
+ this.handleShiftSelection(select, false);
5442
5637
  this.requestRender();
5638
+ return true;
5443
5639
  }
5444
- moveCursorDown() {
5640
+ moveCursorDown(options) {
5641
+ const select = options?.select ?? false;
5642
+ this.handleShiftSelection(select, true);
5445
5643
  this.editorView.moveDownVisual();
5644
+ this.handleShiftSelection(select, false);
5446
5645
  this.requestRender();
5646
+ return true;
5447
5647
  }
5448
5648
  gotoLine(line) {
5449
5649
  this.editBuffer.gotoLine(line);
5450
5650
  this.requestRender();
5451
5651
  }
5452
- gotoLineEnd() {
5652
+ gotoLineHome(options) {
5653
+ const select = options?.select ?? false;
5654
+ this.handleShiftSelection(select, true);
5453
5655
  const cursor = this.editorView.getCursor();
5454
- this.editBuffer.gotoLine(9999);
5455
- const afterCursor = this.editorView.getCursor();
5456
- if (afterCursor.row !== cursor.row) {
5457
- this.editBuffer.setCursor(cursor.row, 9999);
5458
- }
5656
+ this.editBuffer.setCursor(cursor.row, 0);
5657
+ this.handleShiftSelection(select, false);
5658
+ this.requestRender();
5659
+ return true;
5660
+ }
5661
+ gotoLineEnd(options) {
5662
+ const select = options?.select ?? false;
5663
+ this.handleShiftSelection(select, true);
5664
+ const eol = this.editBuffer.getEOL();
5665
+ this.editBuffer.setCursor(eol.row, eol.col);
5666
+ this.handleShiftSelection(select, false);
5459
5667
  this.requestRender();
5668
+ return true;
5669
+ }
5670
+ gotoBufferHome() {
5671
+ this.editBuffer.setCursor(0, 0);
5672
+ this.requestRender();
5673
+ return true;
5460
5674
  }
5461
5675
  gotoBufferEnd() {
5462
5676
  this.editBuffer.gotoLine(999999);
5463
5677
  this.requestRender();
5678
+ return true;
5464
5679
  }
5465
5680
  deleteToLineEnd() {
5466
5681
  const cursor = this.editorView.getCursor();
5467
- const startCol = cursor.col;
5468
- const tempCursor = this.editorView.getCursor();
5469
- this.editBuffer.setCursor(tempCursor.row, 9999);
5470
- const endCursor = this.editorView.getCursor();
5471
- const endCol = endCursor.col;
5472
- this.editBuffer.setCursor(cursor.row, startCol);
5473
- if (endCol > startCol) {
5474
- for (let i = 0;i < endCol - startCol; i++) {
5475
- this.deleteChar();
5476
- }
5682
+ const eol = this.editBuffer.getEOL();
5683
+ if (eol.col > cursor.col) {
5684
+ this.editBuffer.deleteRange(cursor.row, cursor.col, eol.row, eol.col);
5477
5685
  }
5478
5686
  this.requestRender();
5687
+ return true;
5479
5688
  }
5480
5689
  undo() {
5481
5690
  this._ctx.clearSelection();
5482
5691
  this.editBuffer.undo();
5483
5692
  this.requestRender();
5693
+ return true;
5484
5694
  }
5485
5695
  redo() {
5486
5696
  this._ctx.clearSelection();
5487
5697
  this.editBuffer.redo();
5488
5698
  this.requestRender();
5699
+ return true;
5700
+ }
5701
+ moveWordForward(options) {
5702
+ const select = options?.select ?? false;
5703
+ this.handleShiftSelection(select, true);
5704
+ const nextWord = this.editBuffer.getNextWordBoundary();
5705
+ this.editBuffer.setCursorByOffset(nextWord.offset);
5706
+ this.handleShiftSelection(select, false);
5707
+ this.requestRender();
5708
+ return true;
5709
+ }
5710
+ moveWordBackward(options) {
5711
+ const select = options?.select ?? false;
5712
+ this.handleShiftSelection(select, true);
5713
+ const prevWord = this.editBuffer.getPrevWordBoundary();
5714
+ this.editBuffer.setCursorByOffset(prevWord.offset);
5715
+ this.handleShiftSelection(select, false);
5716
+ this.requestRender();
5717
+ return true;
5718
+ }
5719
+ deleteWordForward() {
5720
+ if (this.hasSelection()) {
5721
+ this.deleteSelectedText();
5722
+ return true;
5723
+ }
5724
+ const currentCursor = this.editBuffer.getCursorPosition();
5725
+ const nextWord = this.editBuffer.getNextWordBoundary();
5726
+ if (nextWord.offset > currentCursor.offset) {
5727
+ this.editBuffer.deleteRange(currentCursor.row, currentCursor.col, nextWord.row, nextWord.col);
5728
+ }
5729
+ this._ctx.clearSelection();
5730
+ this.requestRender();
5731
+ return true;
5732
+ }
5733
+ deleteWordBackward() {
5734
+ if (this.hasSelection()) {
5735
+ this.deleteSelectedText();
5736
+ return true;
5737
+ }
5738
+ const currentCursor = this.editBuffer.getCursorPosition();
5739
+ const prevWord = this.editBuffer.getPrevWordBoundary();
5740
+ if (prevWord.offset < currentCursor.offset) {
5741
+ this.editBuffer.deleteRange(prevWord.row, prevWord.col, currentCursor.row, currentCursor.col);
5742
+ }
5743
+ this._ctx.clearSelection();
5744
+ this.requestRender();
5745
+ return true;
5489
5746
  }
5490
5747
  handleShiftSelection(shiftPressed, isBeforeMovement) {
5491
5748
  if (!this.selectable)
@@ -5520,7 +5777,7 @@ class TextareaRenderable extends EditBufferRenderable {
5520
5777
  set placeholder(value) {
5521
5778
  if (this._placeholder !== value) {
5522
5779
  this._placeholder = value;
5523
- this.editBuffer.setPlaceholder(value);
5780
+ this.applyPlaceholder(value);
5524
5781
  this.requestRender();
5525
5782
  }
5526
5783
  }
@@ -5558,43 +5815,30 @@ class TextareaRenderable extends EditBufferRenderable {
5558
5815
  this.updateColors();
5559
5816
  }
5560
5817
  }
5561
- set placeholderColor(value) {
5562
- const newColor = parseColor(value ?? TextareaRenderable.defaults.placeholderColor);
5563
- if (this._placeholderColor !== newColor) {
5564
- this._placeholderColor = newColor;
5565
- this.editBuffer.setPlaceholderColor(newColor);
5566
- this.requestRender();
5818
+ set initialValue(value) {
5819
+ if (!this._initialValueSet) {
5820
+ this.setText(value);
5821
+ this._initialValueSet = true;
5567
5822
  }
5568
5823
  }
5569
- get cursorOffset() {
5570
- return this.editorView.getVisualCursor().offset;
5571
- }
5572
- set cursorOffset(offset) {
5573
- this.editorView.setCursorByOffset(offset);
5574
- this.requestRender();
5575
- }
5576
- addHighlight(lineIdx, highlight) {
5577
- this.editBuffer.addHighlight(lineIdx, highlight);
5578
- this.requestRender();
5579
- }
5580
- addHighlightByCharRange(highlight) {
5581
- this.editBuffer.addHighlightByCharRange(highlight);
5582
- this.requestRender();
5824
+ submit() {
5825
+ if (this._submitListener) {
5826
+ this._submitListener({});
5827
+ }
5828
+ return true;
5583
5829
  }
5584
- removeHighlightsByRef(hlRef) {
5585
- this.editBuffer.removeHighlightsByRef(hlRef);
5586
- this.requestRender();
5830
+ set onSubmit(handler) {
5831
+ this._submitListener = handler;
5587
5832
  }
5588
- clearLineHighlights(lineIdx) {
5589
- this.editBuffer.clearLineHighlights(lineIdx);
5590
- this.requestRender();
5833
+ get onSubmit() {
5834
+ return this._submitListener;
5591
5835
  }
5592
- clearAllHighlights() {
5593
- this.editBuffer.clearAllHighlights();
5594
- this.requestRender();
5836
+ set keyBindings(bindings) {
5837
+ const mergedBindings = mergeKeyBindings(defaultTextareaKeybindings, bindings);
5838
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings);
5595
5839
  }
5596
- getLineHighlights(lineIdx) {
5597
- return this.editBuffer.getLineHighlights(lineIdx);
5840
+ get extmarks() {
5841
+ return this.editorView.extmarks;
5598
5842
  }
5599
5843
  }
5600
5844
  export {
@@ -5668,6 +5912,7 @@ export {
5668
5912
  cyan,
5669
5913
  createTimeline,
5670
5914
  createTextAttributes,
5915
+ createExtmarksController,
5671
5916
  createCliRenderer,
5672
5917
  coordinateToCharacterIndex,
5673
5918
  convertThemeToStyles,
@@ -5754,6 +5999,7 @@ export {
5754
5999
  Generic,
5755
6000
  FrameBufferRenderable,
5756
6001
  FrameBuffer,
6002
+ ExtmarksController,
5757
6003
  EditorView,
5758
6004
  EditBuffer,
5759
6005
  DistortionEffect,
@@ -5777,5 +6023,5 @@ export {
5777
6023
  ASCIIFont
5778
6024
  };
5779
6025
 
5780
- //# debugId=B4995BB40805F64B64756E2164756E21
6026
+ //# debugId=F972C01B99F2CD0364756E2164756E21
5781
6027
  //# sourceMappingURL=index.js.map