Browse Source

Line length limit set to ((actual max line length) mod 64+2)*64.

Margers 1 month ago
parent
commit
99f03e8008
2 changed files with 34 additions and 3 deletions
  1. 23 2
      packages/ide/wcedit.pas
  2. 11 1
      packages/ide/weditor.pas

+ 23 - 2
packages/ide/wcedit.pas

@@ -72,6 +72,7 @@ type
     TCodeEditorCore = object(TCustomCodeEditorCore)
     TCodeEditorCore = object(TCustomCodeEditorCore)
     protected
     protected
       Lines      : PLineCollection;
       Lines      : PLineCollection;
+      MaxDispLen : Cardinal;
       CanUndo    : Boolean;
       CanUndo    : Boolean;
       StoreUndo  : boolean;
       StoreUndo  : boolean;
       Modified   : Boolean;
       Modified   : Boolean;
@@ -107,6 +108,7 @@ type
       procedure   ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: sw_astring); virtual;
       procedure   ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: sw_astring); virtual;
     public
     public
       { Text & info storage abstraction }
       { Text & info storage abstraction }
+      function    GetMaxDisplayLength: sw_integer; virtual;
       function    GetLineCount: sw_integer; virtual;
       function    GetLineCount: sw_integer; virtual;
       function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
       function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
       function    GetLineText(LineNo: sw_integer): sw_AString; virtual;
       function    GetLineText(LineNo: sw_integer): sw_AString; virtual;
@@ -180,6 +182,7 @@ type
     public
     public
 {      ChangedLine : sw_integer;}
 {      ChangedLine : sw_integer;}
       { Text & info storage abstraction }
       { Text & info storage abstraction }
+      function    GetMaxDisplayLength: sw_integer; virtual;
       function    GetLineCount: sw_integer; virtual;
       function    GetLineCount: sw_integer; virtual;
       function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
       function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
       function    CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
       function    CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
@@ -393,6 +396,7 @@ begin
   new(UndoList,init(500,1000));
   new(UndoList,init(500,1000));
   new(RedoList,init(500,1000));
   new(RedoList,init(500,1000));
   New(Lines, Init(500,1000));
   New(Lines, Init(500,1000));
+  MaxDispLen:=0;
   TabSize:=DefaultTabSize;
   TabSize:=DefaultTabSize;
   IndentSize:=DefaultIndentSize;
   IndentSize:=DefaultIndentSize;
   OnDiskLoadTime:=0;
   OnDiskLoadTime:=0;
@@ -406,6 +410,11 @@ begin
   Lines:=ALines;
   Lines:=ALines;
 end;
 end;
 
 
+function TCodeEditorCore.GetMaxDisplayLength: sw_integer;
+begin
+  GetMaxDisplayLength:=MaxDispLen;
+end;
+
 function TCodeEditorCore.GetLineCount: sw_integer;
 function TCodeEditorCore.GetLineCount: sw_integer;
 begin
 begin
   GetLineCount:=Lines^.Count;
   GetLineCount:=Lines^.Count;
@@ -570,6 +579,7 @@ procedure TCodeEditorCore.SetLineText(I: sw_integer;const S: sw_AString);
 var
 var
   L : PCustomLine;
   L : PCustomLine;
   AddCount : Sw_Integer;
   AddCount : Sw_Integer;
+  DS : sw_AString;
 begin
 begin
   AddCount:=0;
   AddCount:=0;
   while (Lines^.Count<I+1) do
   while (Lines^.Count<I+1) do
@@ -577,10 +587,16 @@ begin
      LinesInsert(-1,New(PLine, Init(@Self,'',0)));
      LinesInsert(-1,New(PLine, Init(@Self,'',0)));
      Inc(AddCount);
      Inc(AddCount);
    end;
    end;
-  if AddCount>0 then
-   LimitsChanged;
   L:=Lines^.At(I);
   L:=Lines^.At(I);
   L^.SetText(S);
   L^.SetText(S);
+  DS:=GetDisplayText(I);
+  if MaxDispLen<Length(DS) then
+  begin
+    MaxDispLen:=Length(DS);
+    inc(AddCount); { indicate to call LimitChanged }
+  end;
+  if AddCount>0 then
+    LimitsChanged;
   ContentsChanged;
   ContentsChanged;
 end;
 end;
 
 
@@ -1003,6 +1019,11 @@ begin
   DrawView;
   DrawView;
 end;
 end;
 
 
+function TCodeEditor.GetMaxDisplayLength: sw_integer;
+begin
+  GetMaxDisplayLength:=Core^.GetMaxDisplayLength;
+end;
+
 function TCodeEditor.GetLineCount: sw_integer;
 function TCodeEditor.GetLineCount: sw_integer;
 begin
 begin
   GetLineCount:=Core^.GetLineCount;
   GetLineCount:=Core^.GetLineCount;

+ 11 - 1
packages/ide/weditor.pas

@@ -562,6 +562,7 @@ type
       procedure   UnLock; virtual;
       procedure   UnLock; virtual;
     public
     public
       { Text & info storage abstraction }
       { Text & info storage abstraction }
+   {a}function    GetMaxDisplayLength: sw_integer; virtual; {Max display code points}
    {a}function    GetLineCount: sw_integer; virtual;
    {a}function    GetLineCount: sw_integer; virtual;
    {a}function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
    {a}function    GetLine(LineNo: sw_integer): PCustomLine; virtual;
    {a}function    CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
    {a}function    CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
@@ -3049,6 +3050,12 @@ begin
   IsClipboard:=false;
   IsClipboard:=false;
 end;
 end;
 
 
+function TCustomCodeEditor.GetMaxDisplayLength: sw_integer;
+begin
+  Abstract;
+  GetMaxDisplayLength:=0;
+end;
+
 function TCustomCodeEditor.GetLineCount: sw_integer;
 function TCustomCodeEditor.GetLineCount: sw_integer;
 begin
 begin
   Abstract;
   Abstract;
@@ -3634,8 +3641,11 @@ begin
 end;
 end;
 
 
 procedure TCustomCodeEditor.DoLimitsChanged;
 procedure TCustomCodeEditor.DoLimitsChanged;
+var DisplayLength : sw_integer;
 begin
 begin
-  SetLimit(MaxLineLength+1,EditorToViewLine(GetLineCount));
+  DisplayLength:=((GetMaxDisplayLength+128) shr 6) shl 6;
+  DisplayLength:=Min(DisplayLength,MaxLineLength+1);
+  SetLimit(DisplayLength,EditorToViewLine(GetLineCount));
 end;
 end;
 
 
 procedure TCustomCodeEditor.BindingsChanged;
 procedure TCustomCodeEditor.BindingsChanged;