@vuu-ui/vuu-codemirror 0.8.4-debug → 0.8.5-debug

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/esm/index.js CHANGED
@@ -3891,6 +3891,9 @@ function atElementStart(doc2, selection) {
3891
3891
  }
3892
3892
  }
3893
3893
  }
3894
+ function isScrolledToBottom(elt) {
3895
+ return elt.scrollTop > Math.max(1, elt.scrollHeight - elt.clientHeight - 4);
3896
+ }
3894
3897
  var DOMPos = class {
3895
3898
  constructor(node, offset, precise = true) {
3896
3899
  this.node = node;
@@ -3938,7 +3941,7 @@ var ContentView = class {
3938
3941
  let prev = null, next;
3939
3942
  for (let child of this.children) {
3940
3943
  if (child.dirty) {
3941
- if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild)) {
3944
+ if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild) && next != view.docView.compositionNode) {
3942
3945
  let contentView = ContentView.get(next);
3943
3946
  if (!contentView || !contentView.parent && contentView.canReuseDOM(child))
3944
3947
  child.reuseDOM(next);
@@ -6002,6 +6005,7 @@ var DocView = class extends ContentView {
6002
6005
  super();
6003
6006
  this.view = view;
6004
6007
  this.compositionDeco = Decoration.none;
6008
+ this.compositionNode = null;
6005
6009
  this.decorations = [];
6006
6010
  this.dynamicDecorationMap = [];
6007
6011
  this.minWidth = 0;
@@ -6031,10 +6035,7 @@ var DocView = class extends ContentView {
6031
6035
  this.minWidthTo = update.changes.mapPos(this.minWidthTo, 1);
6032
6036
  }
6033
6037
  }
6034
- if (this.view.inputState.composing < 0)
6035
- this.compositionDeco = Decoration.none;
6036
- else if (update.transactions.length || this.dirty)
6037
- this.compositionDeco = computeCompositionDeco(this.view, update.changes);
6038
+ ({ deco: this.compositionDeco, node: this.compositionNode } = this.view.inputState.composing < 0 ? noComp : computeCompositionDeco(this.view, update.changes));
6038
6039
  if ((browser.ie || browser.chrome) && !this.compositionDeco.size && update && update.state.doc.lines != update.startState.doc.lines)
6039
6040
  this.forceSelection = true;
6040
6041
  let prevDeco = this.decorations, deco = this.updateDeco();
@@ -6385,10 +6386,11 @@ function compositionSurroundingNode(view) {
6385
6386
  return { from, to: from + cView.length, node: cView.dom, text: textNode };
6386
6387
  }
6387
6388
  }
6389
+ var noComp = { deco: Decoration.none, node: null };
6388
6390
  function computeCompositionDeco(view, changes) {
6389
6391
  let surrounding = compositionSurroundingNode(view);
6390
6392
  if (!surrounding)
6391
- return Decoration.none;
6393
+ return noComp;
6392
6394
  let { from, to, node, text: textNode } = surrounding;
6393
6395
  let newFrom = changes.mapPos(from, 1), newTo = Math.max(newFrom, changes.mapPos(to, -1));
6394
6396
  let { state } = view, reader = new DOMReader([], state);
@@ -6398,23 +6400,24 @@ function computeCompositionDeco(view, changes) {
6398
6400
  reader.readRange(node.firstChild, null);
6399
6401
  let { text } = reader;
6400
6402
  if (text.indexOf(LineBreakPlaceholder) > -1)
6401
- return Decoration.none;
6403
+ return noComp;
6402
6404
  if (newTo - newFrom < text.length) {
6403
6405
  if (state.doc.sliceString(newFrom, Math.min(state.doc.length, newFrom + text.length)) == text)
6404
6406
  newTo = newFrom + text.length;
6405
6407
  else if (state.doc.sliceString(Math.max(0, newTo - text.length), newTo) == text)
6406
6408
  newFrom = newTo - text.length;
6407
6409
  else
6408
- return Decoration.none;
6410
+ return noComp;
6409
6411
  } else if (state.doc.sliceString(newFrom, newTo) != text) {
6410
- return Decoration.none;
6412
+ return noComp;
6411
6413
  }
6412
6414
  let topView = ContentView.get(node);
6413
6415
  if (topView instanceof CompositionView)
6414
6416
  topView = topView.widget.topView;
6415
6417
  else if (topView)
6416
6418
  topView.parent = null;
6417
- return Decoration.set(Decoration.replace({ widget: new CompositionWidget(node, textNode, topView), inclusive: true }).range(newFrom, newTo));
6419
+ let deco = Decoration.set(Decoration.replace({ widget: new CompositionWidget(node, textNode, topView), inclusive: true }).range(newFrom, newTo));
6420
+ return { deco, node };
6418
6421
  }
6419
6422
  var CompositionWidget = class extends WidgetType {
6420
6423
  constructor(top2, text, topView) {
@@ -7004,6 +7007,7 @@ var InputState = class {
7004
7007
  var PendingKeys = [
7005
7008
  { key: "Backspace", keyCode: 8, inputType: "deleteContentBackward" },
7006
7009
  { key: "Enter", keyCode: 13, inputType: "insertParagraph" },
7010
+ { key: "Enter", keyCode: 13, inputType: "insertLineBreak" },
7007
7011
  { key: "Delete", keyCode: 46, inputType: "deleteContentForward" }
7008
7012
  ];
7009
7013
  var EmacsyPendingKeys = "dthko";
@@ -7235,7 +7239,7 @@ handlers.mousedown = (view, event) => {
7235
7239
  if (!style && event.button == 0)
7236
7240
  style = basicMouseSelection(view, event);
7237
7241
  if (style) {
7238
- let mustFocus = view.root.activeElement != view.contentDOM;
7242
+ let mustFocus = !view.hasFocus;
7239
7243
  view.inputState.startMouseSelection(new MouseSelection(view, event, style, mustFocus));
7240
7244
  if (mustFocus)
7241
7245
  view.observer.ignore(() => focusPreventScroll(view.contentDOM));
@@ -8353,7 +8357,7 @@ var ViewState = class {
8353
8357
  let contentChanges = update.changedRanges;
8354
8358
  let heightChanges = ChangedRange.extendWithRanges(contentChanges, heightRelevantDecoChanges(prevDeco, this.stateDeco, update ? update.changes : ChangeSet.empty(this.state.doc.length)));
8355
8359
  let prevHeight = this.heightMap.height;
8356
- let scrollAnchor = this.scrolledToBottom ? null : this.lineBlockAtHeight(this.scrollTop);
8360
+ let scrollAnchor = this.scrolledToBottom ? null : this.scrollAnchorAt(this.scrollTop);
8357
8361
  this.heightMap = this.heightMap.applyChanges(this.stateDeco, update.startState.doc, this.heightOracle.setDoc(this.state.doc), heightChanges);
8358
8362
  if (this.heightMap.height != prevHeight)
8359
8363
  update.flags |= 2;
@@ -8407,7 +8411,7 @@ var ViewState = class {
8407
8411
  this.scrollAnchorHeight = -1;
8408
8412
  this.scrollTop = view.scrollDOM.scrollTop;
8409
8413
  }
8410
- this.scrolledToBottom = this.scrollTop > view.scrollDOM.scrollHeight - view.scrollDOM.clientHeight - 4;
8414
+ this.scrolledToBottom = isScrolledToBottom(view.scrollDOM);
8411
8415
  let pixelViewport = (this.printing ? fullPixelRange : visiblePixelRange)(dom, this.paddingTop);
8412
8416
  let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
8413
8417
  this.pixelViewport = pixelViewport;
@@ -8640,6 +8644,10 @@ var ViewState = class {
8640
8644
  lineBlockAtHeight(height) {
8641
8645
  return scaleBlock(this.heightMap.lineAt(this.scaler.fromDOM(height), QueryType.ByHeight, this.heightOracle, 0, 0), this.scaler);
8642
8646
  }
8647
+ scrollAnchorAt(scrollTop) {
8648
+ let block = this.lineBlockAtHeight(scrollTop + 8);
8649
+ return block.from >= this.viewport.from || this.viewportLines[0].top - scrollTop > 200 ? block : this.viewportLines[0];
8650
+ }
8643
8651
  elementAtHeight(height) {
8644
8652
  return scaleBlock(this.heightMap.blockAt(this.scaler.fromDOM(height), this.heightOracle, 0, 0), this.scaler);
8645
8653
  }
@@ -9881,21 +9889,22 @@ var EditorView = class {
9881
9889
  let updated = null;
9882
9890
  let sDOM = this.scrollDOM, { scrollTop } = sDOM;
9883
9891
  let { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
9892
+ if (scrollTop != this.viewState.scrollTop)
9893
+ scrollAnchorHeight = -1;
9884
9894
  this.viewState.scrollAnchorHeight = -1;
9885
- if (scrollAnchorHeight < 0 || scrollTop != this.viewState.scrollTop) {
9886
- if (scrollTop > sDOM.scrollHeight - sDOM.clientHeight - 4) {
9887
- scrollAnchorPos = -1;
9888
- scrollAnchorHeight = this.viewState.heightMap.height;
9889
- } else {
9890
- let block = this.viewState.lineBlockAtHeight(scrollTop);
9891
- scrollAnchorPos = block.from;
9892
- scrollAnchorHeight = block.top;
9893
- }
9894
- }
9895
9895
  try {
9896
9896
  for (let i = 0; ; i++) {
9897
+ if (scrollAnchorHeight < 0) {
9898
+ if (isScrolledToBottom(sDOM)) {
9899
+ scrollAnchorPos = -1;
9900
+ scrollAnchorHeight = this.viewState.heightMap.height;
9901
+ } else {
9902
+ let block = this.viewState.scrollAnchorAt(scrollTop);
9903
+ scrollAnchorPos = block.from;
9904
+ scrollAnchorHeight = block.top;
9905
+ }
9906
+ }
9897
9907
  this.updateState = 1;
9898
- let oldViewport = this.viewport;
9899
9908
  let changed = this.viewState.measure(this);
9900
9909
  if (!changed && !this.measureRequests.length && this.viewState.scrollTarget == null)
9901
9910
  break;
@@ -9914,7 +9923,7 @@ var EditorView = class {
9914
9923
  return BadMeasure;
9915
9924
  }
9916
9925
  });
9917
- let update = ViewUpdate.create(this, this.state, []), redrawn = false, scrolled = false;
9926
+ let update = ViewUpdate.create(this, this.state, []), redrawn = false;
9918
9927
  update.flags |= changed;
9919
9928
  if (!updated)
9920
9929
  updated = update;
@@ -9937,25 +9946,26 @@ var EditorView = class {
9937
9946
  logException(this.state, e);
9938
9947
  }
9939
9948
  }
9940
- if (this.viewState.editorHeight) {
9941
- if (this.viewState.scrollTarget) {
9942
- this.docView.scrollIntoView(this.viewState.scrollTarget);
9943
- this.viewState.scrollTarget = null;
9944
- scrolled = true;
9945
- } else if (scrollAnchorHeight > -1) {
9946
- let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height : this.viewState.lineBlockAt(scrollAnchorPos).top;
9947
- let diff = newAnchorHeight - scrollAnchorHeight;
9948
- if (diff > 1 || diff < -1) {
9949
- sDOM.scrollTop = scrollTop + diff;
9950
- scrolled = true;
9951
- }
9952
- }
9953
- }
9954
9949
  if (redrawn)
9955
9950
  this.docView.updateSelection(true);
9956
- if (this.viewport.from == oldViewport.from && this.viewport.to == oldViewport.to && !scrolled && this.measureRequests.length == 0)
9951
+ if (!update.viewportChanged && this.measureRequests.length == 0) {
9952
+ if (this.viewState.editorHeight) {
9953
+ if (this.viewState.scrollTarget) {
9954
+ this.docView.scrollIntoView(this.viewState.scrollTarget);
9955
+ this.viewState.scrollTarget = null;
9956
+ continue;
9957
+ } else {
9958
+ let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height : this.viewState.lineBlockAt(scrollAnchorPos).top;
9959
+ let diff = newAnchorHeight - scrollAnchorHeight;
9960
+ if (diff > 1 || diff < -1) {
9961
+ scrollTop = sDOM.scrollTop = scrollTop + diff;
9962
+ scrollAnchorHeight = -1;
9963
+ continue;
9964
+ }
9965
+ }
9966
+ }
9957
9967
  break;
9958
- scrollAnchorHeight = -1;
9968
+ }
9959
9969
  }
9960
9970
  } finally {
9961
9971
  this.updateState = 0;