From: Jean-Philippe Bruyère Date: Thu, 27 Feb 2025 18:40:18 +0000 (+0100) Subject: debug folds scrolling, node lengths X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=7dda55851fd3e9398295a8e2d80c9db884ac6ae6;p=jp%2Fcrowedit.git debug folds scrolling, node lengths --- diff --git a/CrowEditBase/src/Compiler/SyntaxAnalyser.cs b/CrowEditBase/src/Compiler/SyntaxAnalyser.cs index 99bfe7c..98a4117 100644 --- a/CrowEditBase/src/Compiler/SyntaxAnalyser.cs +++ b/CrowEditBase/src/Compiler/SyntaxAnalyser.cs @@ -82,22 +82,19 @@ namespace CrowEditBase /// The final token of this node /// the endline number of this node protected void finishCurrentNode (int endTokenOffsetFromCurrentTokIdx = 0) { - int count = tokIdx - currentNode.TokenIndexBase + endTokenOffsetFromCurrentTokIdx; - currentNode.TokenCount = count < 0 ? null : count; + int lastTokOffset = tokIdx - currentNode.TokenIndexBase + endTokenOffsetFromCurrentTokIdx; + currentNode.lastTokenOfset = lastTokOffset < 0 ? null : lastTokOffset; if (endTokenOffsetFromCurrentTokIdx < 0) { Token lastTok = currentNode.LastTokenIndex.HasValue ? Root.GetTokenByIndex(currentNode.LastTokenIndex.Value) : Root.GetTokenByIndex(currentNode.TokenIndexBase); + currentNode.EndLine = lines.GetLocation(lastTok.End).Line; + }else{ + currentNode.EndLine = currentLine; } - //currentNode.EndLine - currentNode.EndLine = currentLine; currentNode = currentNode.Parent; } - /*protected void setEndOfNode (int endTokenOffsetFromCurrentTokIdx = 0, int endLineOffsetFromCurrentLine = 0) { - currentNode.TokenCount = tokIdx - currentNode.TokenIndexBase + endTokenOffsetFromCurrentTokIdx; - currentNode.EndLine = currentLine + endLineOffsetFromCurrentLine; - }*/ protected void setCurrentNodeEndLine (int endLine) => currentNode.EndLine = endLine; protected bool skipTrivia(bool skipLineBreaks = true) { diff --git a/CrowEditBase/src/Compiler/SyntaxNode.cs b/CrowEditBase/src/Compiler/SyntaxNode.cs index 07d5363..31b6f3b 100644 --- a/CrowEditBase/src/Compiler/SyntaxNode.cs +++ b/CrowEditBase/src/Compiler/SyntaxNode.cs @@ -15,10 +15,14 @@ namespace CrowEditBase StartLine = startLine; TokenIndexBase = tokenBase; if (lastTokenIdx.HasValue) - TokenCount = lastTokenIdx - tokenBase; + lastTokenOfset = lastTokenIdx - tokenBase; } bool _isExpanded; + internal int? lastTokenOfset; + internal bool isFolded; + internal int lineCount; + public bool isExpanded { get => _isExpanded; @@ -36,7 +40,7 @@ namespace CrowEditBase public SyntaxNode Parent { get; private set; } public int StartLine { get; private set; } public virtual int LineCount => lineCount; - public virtual bool IsComplete => TokenCount.HasValue; + public virtual bool IsComplete => lastTokenOfset.HasValue; public virtual bool IsFoldable => IsComplete && !(Parent != Root && Parent.StartLine == StartLine) && lineCount > 1; public virtual SyntaxRootNode Root => Parent.Root; public virtual void UnfoldToTheTop () { @@ -110,10 +114,8 @@ namespace CrowEditBase } public virtual int TokenIndexBase { get; private set; } - public virtual int? TokenCount { get; internal set; } - public int? LastTokenIndex => TokenIndexBase + TokenCount; - internal bool isFolded; - internal int lineCount; + public virtual int TokenCount => lastTokenOfset.HasValue ? lastTokenOfset.Value + 1 : 0; + public int? LastTokenIndex => lastTokenOfset.HasValue ? TokenIndexBase + lastTokenOfset.Value : null; public int EndLine { internal set { @@ -123,18 +125,9 @@ namespace CrowEditBase } public TextSpan Span { get { - /*if (HasChilds) { - return new TextSpan (children.First().Span.Start, children.Last().Span.End) - }*/ - try { - Token startTok = getTokenByIndex(TokenIndexBase); - Token endTok = TokenCount.HasValue ? getTokenByIndex (TokenIndexBase+TokenCount.Value) : startTok; - return new TextSpan (startTok.Start, endTok.End); - }catch{ - System.Diagnostics.Debugger.Break (); - } - return default; - + Token startTok = getTokenByIndex(TokenIndexBase); + Token endTok = LastTokenIndex.HasValue ? getTokenByIndex (LastTokenIndex.Value) : startTok; + return new TextSpan (startTok.Start, endTok.End); } } public SyntaxNode AddChild (SyntaxNode child) { @@ -147,7 +140,7 @@ namespace CrowEditBase child.Parent = null; } public IEnumerable GetChilds () => children.OfType(); - + /* public void Replace (SyntaxNode newNode) { Parent.replaceChild (this, newNode); } @@ -155,7 +148,7 @@ namespace CrowEditBase int idx = children.IndexOf (oldNode); children[idx] = newNode; newNode.Parent = this; - int tokIdxDiff = newNode.TokenCount.Value - oldNode.TokenCount.Value; + int tokIdxDiff = newNode.TokenCount - oldNode.TokenCount; int lineDiff = newNode.EndLine - oldNode.EndLine; if (tokIdxDiff == 0 && lineDiff == 0) return; @@ -171,7 +164,7 @@ namespace CrowEditBase idx = curNode.Parent.children.IndexOf (curNode); curNode = curNode.Parent; } - } + }*/ void offset (int tokenOffset, int lineOffset) { TokenIndexBase += tokenOffset; StartLine += lineOffset; diff --git a/CrowEditBase/src/Compiler/SyntaxRootNode.cs b/CrowEditBase/src/Compiler/SyntaxRootNode.cs index 17d41f0..af0f9ab 100644 --- a/CrowEditBase/src/Compiler/SyntaxRootNode.cs +++ b/CrowEditBase/src/Compiler/SyntaxRootNode.cs @@ -14,7 +14,7 @@ namespace CrowEditBase protected readonly ReadOnlyMemory source; protected Token[] tokens; public override int TokenIndexBase => 0; - public override int? TokenCount { get => tokens == null ? default : Math.Max (0, tokens.Length - 1); internal set {} } + public override int TokenCount => tokens == null ? 0 : Math.Max (0, tokens.Length - 1); public override SyntaxRootNode Root => this; public override bool IsFoldable => false; public override SyntaxNode NextSiblingOrParentsNextSibling => null; diff --git a/CrowEditBase/src/SourceEditor.cs b/CrowEditBase/src/SourceEditor.cs index ce94796..9f9bf24 100644 --- a/CrowEditBase/src/SourceEditor.cs +++ b/CrowEditBase/src/SourceEditor.cs @@ -618,25 +618,22 @@ namespace Crow int printedLines = 0; - int curLine = (int)Math.Floor(ScrollY / lineHeight); - pixY = -(ScrollY % lineHeight); - + int linesToSkip = (int)Math.Floor(ScrollY / lineHeight); IEnumerator foldsEnum = doc.Root.VisibleFoldableNodes.GetEnumerator (); bool notEndOfFolds = foldsEnum.MoveNext(); - while (curLine < doc.LinesCount && printedLines < Math.Min(visibleLines, doc.LinesCount)) { - + while (notEndOfFolds && foldsEnum.Current.StartLine < linesToSkip) { + if (foldsEnum.Current.isFolded) + linesToSkip += foldsEnum.Current.LineCount-1; + notEndOfFolds = foldsEnum.MoveNext(); + } - while (notEndOfFolds && foldsEnum.Current.StartLine < curLine) { - if (foldsEnum.Current.isFolded && curLine <= foldsEnum.Current.EndLine) - curLine += foldsEnum.Current.LineCount - 1; - notEndOfFolds = foldsEnum.MoveNext(); - } + int curLine = linesToSkip; + pixY = -(ScrollY % lineHeight); - if (curLine >= doc.LinesCount)//could it occurs? - break; - + while (curLine < doc.LinesCount && printedLines < Math.Min(visibleLines, doc.LinesCount)) { + int encodedChar = 0; TextLine curTxtLine = doc.GetLine (curLine); int tokPtr = doc.FindTokenIndexIncludingPosition(curTxtLine.Start); @@ -729,9 +726,18 @@ namespace Crow pixY += lineHeight; printedLines++; - if (curFoldStart && foldsEnum.Current.isFolded) - curLine = foldsEnum.Current.EndLine + 1; - else + if (curFoldStart && curLine == foldsEnum.Current.StartLine){ + if (foldsEnum.Current.isFolded) + curLine += foldsEnum.Current.LineCount; + else + curLine++; + notEndOfFolds = foldsEnum.MoveNext(); + while (notEndOfFolds && foldsEnum.Current.StartLine < curLine) { + /*if (foldsEnum.Current.isFolded && curLine <= foldsEnum.Current.EndLine) + curLine += foldsEnum.Current.LineCount;*/ + notEndOfFolds = foldsEnum.MoveNext(); + } + } else curLine++; } diff --git a/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs b/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs index a6045e5..ee7f780 100644 --- a/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs +++ b/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs @@ -50,7 +50,7 @@ namespace CECrowPlugin.Style tokIdx++; } while (currentNode.Parent != null) { - if (!currentNode.TokenCount.HasValue) + if (!currentNode.LastTokenIndex.HasValue) finishCurrentNode (-1); else currentNode = currentNode.Parent; diff --git a/plugins/CEXmlPlugin/src/Parsing/XmlSyntaxAnalyser.cs b/plugins/CEXmlPlugin/src/Parsing/XmlSyntaxAnalyser.cs index a455fed..770c993 100644 --- a/plugins/CEXmlPlugin/src/Parsing/XmlSyntaxAnalyser.cs +++ b/plugins/CEXmlPlugin/src/Parsing/XmlSyntaxAnalyser.cs @@ -86,10 +86,10 @@ namespace CrowEdit.Xml finishCurrentNode (); finishCurrentNode (); } else { addException ("Open/Close element name mismatch"); - finishCurrentNode (1);//finish eltEndTag->curNode is parent elt + finishCurrentNode ();//finish eltEndTag->curNode is parent elt currentNode.RemoveChild(eltEndTag); - finishCurrentNode (-eltEndTag.TokenCount.Value); //dont credit parent element with those tokens from the non matching end tag - //curNode should be parent element of previous element + finishCurrentNode (-eltEndTag.TokenCount); //dont credit parent element with those tokens from the non matching end tag + //curNode should be parent element of previous element while(currentNode is ElementSyntax esp) { //eltEndTag is out of tree, so Name get threw exception if (string.Equals(esp.StartTag.Name, eltEndTagName, StringComparison.Ordinal)) { @@ -98,7 +98,7 @@ namespace CrowEdit.Xml finishCurrentNode (); break; } else { - finishCurrentNode (-eltEndTag.TokenCount.Value); + finishCurrentNode (-eltEndTag.TokenCount); } } } @@ -140,11 +140,12 @@ namespace CrowEdit.Xml tokIdx++; } while (currentNode.Parent != null) { - if (!currentNode.TokenCount.HasValue) + if (!currentNode.LastTokenIndex.HasValue) finishCurrentNode (-1); else currentNode = currentNode.Parent; } + //check why this is required.. setCurrentNodeEndLine (currentLine); return Root; }