ContextCommands = new CommandGroup (CMDCut, CMDCopy, CMDPaste);
}
- /*protected override CharLocation? SelectionStart {
- get => base.SelectionStart;
- set {
- if (SelectionStart == value)
- return;
- base.SelectionStart = value;
- CMDCopy.CanExecute = CMDCut.CanExecute = !SelectionIsEmpty;
- }
- }*/
-
-
public TextDocument Document {
get => document;
set {
CMDCopy.CanExecute = CMDCut.CanExecute = !SelectionIsEmpty;
}
}
- public virtual int CurrentLine {
+ public int CurrentLine {
get => currentLoc.HasValue ? currentLoc.Value.Line : 0;
set {
if (currentLoc?.Line == value)
CMDCopy.CanExecute = CMDCut.CanExecute = !SelectionIsEmpty;
}
}
- public virtual int CurrentColumn {
+ public int CurrentColumn {
get => currentLoc.HasValue ? currentLoc.Value.Column < 0 ? 0 : currentLoc.Value.Column : 0;
set {
if (CurrentColumn == value)
gr.Translate (ScrollX, ScrollY);
}
- protected int getLineIndex (Point mouseLocalPos) =>
+ protected int getLineIndexFromMousePosition (Point mouseLocalPos) =>
(int)Math.Min (Math.Max (0, Math.Floor ((mouseLocalPos.Y + ScrollY)/ lineHeight)), visualLineCount - 1);
protected int getVisualLineIndex (Point mouseLocalPos) =>
(int)Math.Min (Math.Max (0, Math.Floor (mouseLocalPos.Y / lineHeight)), visibleLines - 1);
+ protected virtual int visualCurrentLine => CurrentLoc.HasValue ? CurrentLoc.Value.Line : 0;
protected virtual void updateHoverLocation (Point mouseLocalPos) {
- int hoverLine = getLineIndex (mouseLocalPos);
+ int hoverLine = getLineIndexFromMousePosition (mouseLocalPos);
NotifyValueChanged("MouseY", mouseLocalPos.Y + ScrollY);
NotifyValueChanged("ScrollY", ScrollY);
NotifyValueChanged("VisibleLines", visibleLines);
}
protected virtual bool cancelLinePrint (double lineHeght, double y, int clientHeight) => false;
RectangleD? textCursor = null;
- protected virtual int visualCurrentLine => CurrentLoc.HasValue ? CurrentLoc.Value.Line : 0;
public virtual bool DrawCursor (Context ctx, out Rectangle rect) {
if (CurrentLoc == null) {
(IFace as CrowEditBase.CrowEditBase).CurrentEditor = this;
}
- /*protected override void onUnfocused (object sender, EventArgs e)
- {
- base.onUnfocused (sender, e);
- RegisterForRedraw ();
- }*/
public override void onMouseEnter (object sender, MouseMoveEventArgs e) {
base.onMouseEnter (sender, e);
if (!Focusable)
leftMargin += leftMarginRightGap;
//updateVisibleColumns ();
}
+
+ protected override CharLocation? CurrentLoc {
+ get => currentLoc;
+ set {
+ if (currentLoc == value)
+ return;
+ currentLoc = value;
+ if (currentLoc.HasValue)
+ getFoldContainingLine (currentLoc.Value.Line)?.UnfoldToTheTop();
+ NotifyValueChanged ("CurrentLine", CurrentLine);
+ NotifyValueChanged ("CurrentColumn", CurrentColumn);
+ CMDCopy.CanExecute = CMDCut.CanExecute = !SelectionIsEmpty;
+ }
+ }
public override int measureRawSize(LayoutingType lt)
{
DbgLogger.StartEvent(DbgEvtType.GOMeasure, this, lt);
hideOverlay ();
if (mouseIsInMargin) {
if (e.Button == MouseButton.Left && mouseIsInFoldRect) {
- SyntaxNode curNode = getFoldFromLine (hoverLoc.Value.Line);
+ SyntaxNode curNode = getFoldStartingAt (hoverLoc.Value.Line);
if (curNode != null) {
curNode.isFolded = !curNode.isFolded;
textMeasureIsUpToDate = false;
base.onMouseDown (sender, e);
}
- SyntaxNode getFoldFromLine (int line) {
- if (!(Document is SourceDocument doc))
- return null;
- IEnumerable<SyntaxNode> folds = doc.SyntaxRootNode.FoldableNodes;
- if (folds == null)
- return null;
- return folds.FirstOrDefault (n => n.StartLine == line);
- }
protected override void mouseMove (MouseEventArgs e) {
Point mLoc = ScreenPointToLocal (e.Position);
if (mLoc.X < leftMargin - leftMarginRightGap) {
RegisterForRedraw ();
}
}
- //int hoverVisualLine, visualLine;
protected override void updateHoverLocation (Point mouseLocalPos) {
- int hoverVisualLine = getLineIndex (mouseLocalPos);
+ int hoverVisualLine = getLineIndexFromMousePosition (mouseLocalPos);
int hoverLine = hoverVisualLine + countFoldedLinesUntil (hoverVisualLine);
NotifyValueChanged("MouseY", mouseLocalPos.Y + ScrollY);
NotifyValueChanged("ScrollY", ScrollY);
updateLocation (gr, ClientRectangle.Width, ref hoverLoc);
}
}
- int getVisualLine (int absoluteLine) {
- if (!(Document is SourceDocument doc))
- return absoluteLine;
- int foldedLines = 0;
- IEnumerator<SyntaxNode> foldsEnum = doc.SyntaxRootNode.FoldableNodes.GetEnumerator();
- bool notEndOfFolds = foldsEnum.MoveNext();
- while (notEndOfFolds && foldsEnum.Current.StartLine < absoluteLine) {
- if (foldsEnum.Current.isFolded) {
- foldedLines += foldsEnum.Current.LineCount - 1;
- SyntaxNode nextNode = foldsEnum.Current.NextSiblingOrParentsNextSibling;
- if (nextNode == null)
- break;
- notEndOfFolds = foldsEnum.MoveNext();
- while (notEndOfFolds && foldsEnum.Current.StartLine < nextNode.StartLine)
- notEndOfFolds = foldsEnum.MoveNext();
- } else
- notEndOfFolds = foldsEnum.MoveNext();
- }
- return absoluteLine - foldedLines;
- }
- int countFoldedLinesUntil (int visualLine) {
- if (!(Document is SourceDocument doc))
- return 0;
- int foldedLines = 0;
- IEnumerator<SyntaxNode> nodeEnum = doc.SyntaxRootNode.FoldableNodes.GetEnumerator ();
- if (!nodeEnum.MoveNext())
- return 0;
-
- int l = 0;
- while (l < visualLine + foldedLines) {
- if (nodeEnum.Current.StartLine == l) {
- if (nodeEnum.Current.isFolded) {
- foldedLines += nodeEnum.Current.lineCount - 1;
- SyntaxNode nextNode = nodeEnum.Current.NextSiblingOrParentsNextSibling;
- if (nextNode == null || !nodeEnum.MoveNext())
- return foldedLines;
-
- while (nodeEnum.Current.StartLine < nextNode.StartLine) {
- if (!nodeEnum.MoveNext())
- return foldedLines;
- }
-
- } else if (!nodeEnum.MoveNext())
- return foldedLines;
- }
- l ++;
- }
- //Console.WriteLine ($"visualLine: {visualLine} foldedLines: {foldedLines}");
- return foldedLines;
- }
-
public override void onKeyDown(object sender, KeyEventArgs e)
{
TextSpan selection = Selection;
base.onKeyDown(sender, e);
}
+
+ SyntaxNode getFoldStartingAt (int line) {
+ if (!(Document is SourceDocument doc))
+ return null;
+ IEnumerable<SyntaxNode> folds = doc.SyntaxRootNode.FoldableNodes;
+ if (folds == null)
+ return null;
+ return folds.FirstOrDefault (n => n.StartLine == line);
+ }
+ SyntaxNode getFoldContainingLine (int line) {
+ if (!(Document is SourceDocument doc))
+ return null;
+ IEnumerable<SyntaxNode> folds = doc.SyntaxRootNode.FoldableNodes;
+ if (folds == null)
+ return null;
+ return folds.LastOrDefault (n => n.StartLine <= line && n.EndLine >= line);
+ }
+
+ int getVisualLine (int absoluteLine) {
+ if (!(Document is SourceDocument doc))
+ return absoluteLine;
+ int foldedLines = 0;
+ IEnumerator<SyntaxNode> foldsEnum = doc.SyntaxRootNode.FoldableNodes.GetEnumerator();
+ bool notEndOfFolds = foldsEnum.MoveNext();
+ while (notEndOfFolds && foldsEnum.Current.StartLine < absoluteLine) {
+ if (foldsEnum.Current.isFolded) {
+ foldedLines += foldsEnum.Current.LineCount - 1;
+ SyntaxNode nextNode = foldsEnum.Current.NextSiblingOrParentsNextSibling;
+ if (nextNode == null)
+ break;
+ notEndOfFolds = foldsEnum.MoveNext();
+ while (notEndOfFolds && foldsEnum.Current.StartLine < nextNode.StartLine)
+ notEndOfFolds = foldsEnum.MoveNext();
+ } else
+ notEndOfFolds = foldsEnum.MoveNext();
+ }
+ return absoluteLine - foldedLines;
+ }
+ int countFoldedLinesUntil (int visualLine) {
+ if (!(Document is SourceDocument doc))
+ return 0;
+ int foldedLines = 0;
+ IEnumerator<SyntaxNode> nodeEnum = doc.SyntaxRootNode.FoldableNodes.GetEnumerator ();
+ if (!nodeEnum.MoveNext())
+ return 0;
+
+ int l = 0;
+ while (l < visualLine + foldedLines) {
+ if (nodeEnum.Current.StartLine == l) {
+ if (nodeEnum.Current.isFolded) {
+ foldedLines += nodeEnum.Current.lineCount - 1;
+ SyntaxNode nextNode = nodeEnum.Current.NextSiblingOrParentsNextSibling;
+ if (nextNode == null || !nodeEnum.MoveNext())
+ return foldedLines;
+
+ while (nodeEnum.Current.StartLine < nextNode.StartLine) {
+ if (!nodeEnum.MoveNext())
+ return foldedLines;
+ }
+
+ } else if (!nodeEnum.MoveNext())
+ return foldedLines;
+ }
+ l ++;
+ }
+ //Console.WriteLine ($"visualLine: {visualLine} foldedLines: {foldedLines}");
+ return foldedLines;
+ }
+
protected override int getAbsoluteLineIndexFromVisualLineMove (int startLine, int visualLineDiff) {
int newVl = Math.Min (Math.Max (0, getVisualLine (startLine) + visualLineDiff), visualLineCount - 1);
return newVl + countFoldedLinesUntil (newVl);
}
- /*public override bool LineMove (int lineDiff) {
- CharLocation loc = CurrentLoc.Value;
- int newLine = getAbsoluteLineIndexFromVisualLineMove (loc.Line, lineDiff);
- if (newLine == loc.Line)
- return false;
- return base.LineMove (newLine - loc.Line);
- }*/
protected override int visualLineCount
{
return;
}
- setFontForContext (gr);
-
- if (!textMeasureIsUpToDate) {
- lock (linesMutex)
- measureTextBounds (gr);
- }
-
double lineHeight = fe.Ascent + fe.Descent;
updateMargin ();