瀏覽代碼

fix: fix json editor remove last line error

DaiQiangReal 5 月之前
父節點
當前提交
c7855dbb93

+ 3 - 1
packages/semi-json-viewer-core/src/model/selectionModel.ts

@@ -189,7 +189,9 @@ export class SelectionModel {
             col = totalOffset;
         }
 
-        row = (lineElement as any).lineNumber || 1;
+        if (lineElement) {
+            row = (lineElement as any).lineNumber || 1;
+        }
         return { row, col: col + 1 };
     }
 

+ 4 - 1
packages/semi-json-viewer-core/src/pieceTreeTextBuffer/pieceTreeBase.ts

@@ -504,7 +504,10 @@ export class PieceTreeBase {
         return value;
     }
 
-    public getValueInRange2(startPosition: NodePosition, endPosition: NodePosition): string {
+    public getValueInRange2(startPosition: NodePosition | null, endPosition: NodePosition | null): string {
+        if (!startPosition || !endPosition) {
+            return "";
+        }
         if (startPosition.node === endPosition.node) {
             const node = startPosition.node;
             const buffer = this._buffers[node.piece.bufferIndex].buffer;