@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/cjs/index.js CHANGED
@@ -3951,6 +3951,9 @@ function atElementStart(doc2, selection) {
3951
3951
  }
3952
3952
  }
3953
3953
  }
3954
+ function isScrolledToBottom(elt) {
3955
+ return elt.scrollTop > Math.max(1, elt.scrollHeight - elt.clientHeight - 4);
3956
+ }
3954
3957
  var DOMPos = class {
3955
3958
  constructor(node, offset, precise = true) {
3956
3959
  this.node = node;
@@ -3998,7 +4001,7 @@ var ContentView = class {
3998
4001
  let prev = null, next;
3999
4002
  for (let child of this.children) {
4000
4003
  if (child.dirty) {
4001
- if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild)) {
4004
+ if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild) && next != view.docView.compositionNode) {
4002
4005
  let contentView = ContentView.get(next);
4003
4006
  if (!contentView || !contentView.parent && contentView.canReuseDOM(child))
4004
4007
  child.reuseDOM(next);
@@ -6062,6 +6065,7 @@ var DocView = class extends ContentView {
6062
6065
  super();
6063
6066
  this.view = view;
6064
6067
  this.compositionDeco = Decoration.none;
6068
+ this.compositionNode = null;
6065
6069
  this.decorations = [];
6066
6070
  this.dynamicDecorationMap = [];
6067
6071
  this.minWidth = 0;
@@ -6091,10 +6095,7 @@ var DocView = class extends ContentView {
6091
6095
  this.minWidthTo = update.changes.mapPos(this.minWidthTo, 1);
6092
6096
  }
6093
6097
  }
6094
- if (this.view.inputState.composing < 0)
6095
- this.compositionDeco = Decoration.none;
6096
- else if (update.transactions.length || this.dirty)
6097
- this.compositionDeco = computeCompositionDeco(this.view, update.changes);
6098
+ ({ deco: this.compositionDeco, node: this.compositionNode } = this.view.inputState.composing < 0 ? noComp : computeCompositionDeco(this.view, update.changes));
6098
6099
  if ((browser.ie || browser.chrome) && !this.compositionDeco.size && update && update.state.doc.lines != update.startState.doc.lines)
6099
6100
  this.forceSelection = true;
6100
6101
  let prevDeco = this.decorations, deco = this.updateDeco();
@@ -6445,10 +6446,11 @@ function compositionSurroundingNode(view) {
6445
6446
  return { from, to: from + cView.length, node: cView.dom, text: textNode };
6446
6447
  }
6447
6448
  }
6449
+ var noComp = { deco: Decoration.none, node: null };
6448
6450
  function computeCompositionDeco(view, changes) {
6449
6451
  let surrounding = compositionSurroundingNode(view);
6450
6452
  if (!surrounding)
6451
- return Decoration.none;
6453
+ return noComp;
6452
6454
  let { from, to, node, text: textNode } = surrounding;
6453
6455
  let newFrom = changes.mapPos(from, 1), newTo = Math.max(newFrom, changes.mapPos(to, -1));
6454
6456
  let { state } = view, reader = new DOMReader([], state);
@@ -6458,23 +6460,24 @@ function computeCompositionDeco(view, changes) {
6458
6460
  reader.readRange(node.firstChild, null);
6459
6461
  let { text } = reader;
6460
6462
  if (text.indexOf(LineBreakPlaceholder) > -1)
6461
- return Decoration.none;
6463
+ return noComp;
6462
6464
  if (newTo - newFrom < text.length) {
6463
6465
  if (state.doc.sliceString(newFrom, Math.min(state.doc.length, newFrom + text.length)) == text)
6464
6466
  newTo = newFrom + text.length;
6465
6467
  else if (state.doc.sliceString(Math.max(0, newTo - text.length), newTo) == text)
6466
6468
  newFrom = newTo - text.length;
6467
6469
  else
6468
- return Decoration.none;
6470
+ return noComp;
6469
6471
  } else if (state.doc.sliceString(newFrom, newTo) != text) {
6470
- return Decoration.none;
6472
+ return noComp;
6471
6473
  }
6472
6474
  let topView = ContentView.get(node);
6473
6475
  if (topView instanceof CompositionView)
6474
6476
  topView = topView.widget.topView;
6475
6477
  else if (topView)
6476
6478
  topView.parent = null;
6477
- return Decoration.set(Decoration.replace({ widget: new CompositionWidget(node, textNode, topView), inclusive: true }).range(newFrom, newTo));
6479
+ let deco = Decoration.set(Decoration.replace({ widget: new CompositionWidget(node, textNode, topView), inclusive: true }).range(newFrom, newTo));
6480
+ return { deco, node };
6478
6481
  }
6479
6482
  var CompositionWidget = class extends WidgetType {
6480
6483
  constructor(top2, text, topView) {
@@ -7064,6 +7067,7 @@ var InputState = class {
7064
7067
  var PendingKeys = [
7065
7068
  { key: "Backspace", keyCode: 8, inputType: "deleteContentBackward" },
7066
7069
  { key: "Enter", keyCode: 13, inputType: "insertParagraph" },
7070
+ { key: "Enter", keyCode: 13, inputType: "insertLineBreak" },
7067
7071
  { key: "Delete", keyCode: 46, inputType: "deleteContentForward" }
7068
7072
  ];
7069
7073
  var EmacsyPendingKeys = "dthko";
@@ -7295,7 +7299,7 @@ handlers.mousedown = (view, event) => {
7295
7299
  if (!style && event.button == 0)
7296
7300
  style = basicMouseSelection(view, event);
7297
7301
  if (style) {
7298
- let mustFocus = view.root.activeElement != view.contentDOM;
7302
+ let mustFocus = !view.hasFocus;
7299
7303
  view.inputState.startMouseSelection(new MouseSelection(view, event, style, mustFocus));
7300
7304
  if (mustFocus)
7301
7305
  view.observer.ignore(() => focusPreventScroll(view.contentDOM));
@@ -8413,7 +8417,7 @@ var ViewState = class {
8413
8417
  let contentChanges = update.changedRanges;
8414
8418
  let heightChanges = ChangedRange.extendWithRanges(contentChanges, heightRelevantDecoChanges(prevDeco, this.stateDeco, update ? update.changes : ChangeSet.empty(this.state.doc.length)));
8415
8419
  let prevHeight = this.heightMap.height;
8416
- let scrollAnchor = this.scrolledToBottom ? null : this.lineBlockAtHeight(this.scrollTop);
8420
+ let scrollAnchor = this.scrolledToBottom ? null : this.scrollAnchorAt(this.scrollTop);
8417
8421
  this.heightMap = this.heightMap.applyChanges(this.stateDeco, update.startState.doc, this.heightOracle.setDoc(this.state.doc), heightChanges);
8418
8422
  if (this.heightMap.height != prevHeight)
8419
8423
  update.flags |= 2;
@@ -8467,7 +8471,7 @@ var ViewState = class {
8467
8471
  this.scrollAnchorHeight = -1;
8468
8472
  this.scrollTop = view.scrollDOM.scrollTop;
8469
8473
  }
8470
- this.scrolledToBottom = this.scrollTop > view.scrollDOM.scrollHeight - view.scrollDOM.clientHeight - 4;
8474
+ this.scrolledToBottom = isScrolledToBottom(view.scrollDOM);
8471
8475
  let pixelViewport = (this.printing ? fullPixelRange : visiblePixelRange)(dom, this.paddingTop);
8472
8476
  let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
8473
8477
  this.pixelViewport = pixelViewport;
@@ -8700,6 +8704,10 @@ var ViewState = class {
8700
8704
  lineBlockAtHeight(height) {
8701
8705
  return scaleBlock(this.heightMap.lineAt(this.scaler.fromDOM(height), QueryType.ByHeight, this.heightOracle, 0, 0), this.scaler);
8702
8706
  }
8707
+ scrollAnchorAt(scrollTop) {
8708
+ let block = this.lineBlockAtHeight(scrollTop + 8);
8709
+ return block.from >= this.viewport.from || this.viewportLines[0].top - scrollTop > 200 ? block : this.viewportLines[0];
8710
+ }
8703
8711
  elementAtHeight(height) {
8704
8712
  return scaleBlock(this.heightMap.blockAt(this.scaler.fromDOM(height), this.heightOracle, 0, 0), this.scaler);
8705
8713
  }
@@ -9941,21 +9949,22 @@ var EditorView = class {
9941
9949
  let updated = null;
9942
9950
  let sDOM = this.scrollDOM, { scrollTop } = sDOM;
9943
9951
  let { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
9952
+ if (scrollTop != this.viewState.scrollTop)
9953
+ scrollAnchorHeight = -1;
9944
9954
  this.viewState.scrollAnchorHeight = -1;
9945
- if (scrollAnchorHeight < 0 || scrollTop != this.viewState.scrollTop) {
9946
- if (scrollTop > sDOM.scrollHeight - sDOM.clientHeight - 4) {
9947
- scrollAnchorPos = -1;
9948
- scrollAnchorHeight = this.viewState.heightMap.height;
9949
- } else {
9950
- let block = this.viewState.lineBlockAtHeight(scrollTop);
9951
- scrollAnchorPos = block.from;
9952
- scrollAnchorHeight = block.top;
9953
- }
9954
- }
9955
9955
  try {
9956
9956
  for (let i = 0; ; i++) {
9957
+ if (scrollAnchorHeight < 0) {
9958
+ if (isScrolledToBottom(sDOM)) {
9959
+ scrollAnchorPos = -1;
9960
+ scrollAnchorHeight = this.viewState.heightMap.height;
9961
+ } else {
9962
+ let block = this.viewState.scrollAnchorAt(scrollTop);
9963
+ scrollAnchorPos = block.from;
9964
+ scrollAnchorHeight = block.top;
9965
+ }
9966
+ }
9957
9967
  this.updateState = 1;
9958
- let oldViewport = this.viewport;
9959
9968
  let changed = this.viewState.measure(this);
9960
9969
  if (!changed && !this.measureRequests.length && this.viewState.scrollTarget == null)
9961
9970
  break;
@@ -9974,7 +9983,7 @@ var EditorView = class {
9974
9983
  return BadMeasure;
9975
9984
  }
9976
9985
  });
9977
- let update = ViewUpdate.create(this, this.state, []), redrawn = false, scrolled = false;
9986
+ let update = ViewUpdate.create(this, this.state, []), redrawn = false;
9978
9987
  update.flags |= changed;
9979
9988
  if (!updated)
9980
9989
  updated = update;
@@ -9997,25 +10006,26 @@ var EditorView = class {
9997
10006
  logException(this.state, e);
9998
10007
  }
9999
10008
  }
10000
- if (this.viewState.editorHeight) {
10001
- if (this.viewState.scrollTarget) {
10002
- this.docView.scrollIntoView(this.viewState.scrollTarget);
10003
- this.viewState.scrollTarget = null;
10004
- scrolled = true;
10005
- } else if (scrollAnchorHeight > -1) {
10006
- let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height : this.viewState.lineBlockAt(scrollAnchorPos).top;
10007
- let diff = newAnchorHeight - scrollAnchorHeight;
10008
- if (diff > 1 || diff < -1) {
10009
- sDOM.scrollTop = scrollTop + diff;
10010
- scrolled = true;
10011
- }
10012
- }
10013
- }
10014
10009
  if (redrawn)
10015
10010
  this.docView.updateSelection(true);
10016
- if (this.viewport.from == oldViewport.from && this.viewport.to == oldViewport.to && !scrolled && this.measureRequests.length == 0)
10011
+ if (!update.viewportChanged && this.measureRequests.length == 0) {
10012
+ if (this.viewState.editorHeight) {
10013
+ if (this.viewState.scrollTarget) {
10014
+ this.docView.scrollIntoView(this.viewState.scrollTarget);
10015
+ this.viewState.scrollTarget = null;
10016
+ continue;
10017
+ } else {
10018
+ let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height : this.viewState.lineBlockAt(scrollAnchorPos).top;
10019
+ let diff = newAnchorHeight - scrollAnchorHeight;
10020
+ if (diff > 1 || diff < -1) {
10021
+ scrollTop = sDOM.scrollTop = scrollTop + diff;
10022
+ scrollAnchorHeight = -1;
10023
+ continue;
10024
+ }
10025
+ }
10026
+ }
10017
10027
  break;
10018
- scrollAnchorHeight = -1;
10028
+ }
10019
10029
  }
10020
10030
  } finally {
10021
10031
  this.updateState = 0;