//[Test] public void TestCharPosition01() { //Test to make sure origin is correct //Character coordinates input: (0,0) //Screen coordinates expected: (Configurations.LeftMargin, 0) coordinates.SetCharacterPosition(new System.Drawing.Point(0, 0)); Assert.IsTrue((System.Windows.Point)coordinates.GetScreenPosition() == new Point(Configurations.CanvasMarginLeft, 0)); }
//[Test] public void TestCharPositionToNonSpaceCharCount() { // \tb = a + 3; // \t c\t = a + \t b; TextBuffer textBuffer = new TextBuffer("\tb = a + 3;\n\t c\t = a + \t b;"); CharPosition position = new CharPosition(textBuffer); position.SetCharacterPosition(0, 0); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(1, 0); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(2, 0); Assert.AreEqual(1, position.ToNonSpaceCharCount()); position.SetCharacterPosition(8, 0); Assert.AreEqual(4, position.ToNonSpaceCharCount()); position.SetCharacterPosition(0, 1); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(5, 1); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(6, 1); Assert.AreEqual(1, position.ToNonSpaceCharCount()); position.SetCharacterPosition(17, 1); Assert.AreEqual(5, position.ToNonSpaceCharCount()); }
internal void UpdateCaretPosition(bool ensureCursorVisible = true) { if (null == Solution.Current.ActiveScript) { return; } IScriptObject activeScript = Solution.Current.ActiveScript; CharPosition converter = activeScript.CreateCharPosition(); System.Drawing.Point cursorPosition = textCore.CursorPosition; converter.SetCharacterPosition(cursorPosition); textCanvas.SetCursorScreenPos(converter.GetScreenPosition()); if (ensureCursorVisible == true) { textCanvas.EnsureCursorVisible(cursorPosition.X, cursorPosition.Y); } // As the caret is moved around, more often than never the selection also // gets changed. It would make sense to update the visual here at the same time. textCanvas.SetSelectionRange(textCore.SelectionStart, textCore.SelectionEnd); // @TODO(Salman) merge these into one label control. LineCol.Text = "Line: " + Convert.ToString(cursorPosition.Y + 1) + " " + "Col: " + Convert.ToString(cursorPosition.X + 1); }
private void OnDragOver(object sender, DragEventArgs e) { e.Effects = DragDropEffects.Move; if ((e.KeyStates & DragDropKeyStates.ControlKey) != 0) { e.Effects = DragDropEffects.Copy; } // First, validate arbitrary screen coordinates... IScriptObject activeScript = Solution.Current.ActiveScript; CharPosition mousePoint = activeScript.CreateCharPosition(); mousePoint.SetScreenPosition(GetRelativeCanvasPosition(e)); // Here when the content is dragged to the first line in view, try to // bring it onto the previous line. This is so that the previous line // gets to scroll into view later on. If the cursor is on the last // visible line, then try to set it one line beyond that. This is so // that the next line get to scroll into view the same way. // int characterY = mousePoint.CharacterY; int lastVisibleLine = textCanvas.FirstVisibleLine + textCanvas.MaxVisibleLines; if (characterY == textCanvas.FirstVisibleLine) { characterY = characterY - 1; } else if (characterY >= lastVisibleLine - 1) { characterY = characterY + 1; } mousePoint.SetCharacterPosition(mousePoint.CharacterX, characterY); // Then get the precised cursor coordinates, and then set the // character position so we get screen coordinates at character // boundaries... System.Drawing.Point cursor = mousePoint.GetCharacterPosition(); mousePoint.SetCharacterPosition(cursor); textCanvas.SetCursorScreenPos(mousePoint.GetScreenPosition()); textCanvas.EnsureCursorVisible(mousePoint.CharacterX, mousePoint.CharacterY); }
//[Test] public void TestCharPositionFromNonSpaceCharCount() { // \tb = a + 3; // \t c\t = a + \t b; TextBuffer textBuffer = new TextBuffer("\tb = a + 3;\n\t c\t = a + \t b;"); CharPosition position = new CharPosition(textBuffer); position.SetCharacterPosition(0, 0); // First line. position.FromNonSpaceCharCount(1); Assert.AreEqual(2, position.CharacterX); position.FromNonSpaceCharCount(4); Assert.AreEqual(8, position.CharacterX); position.SetCharacterPosition(0, 1); // Second line. position.FromNonSpaceCharCount(1); Assert.AreEqual(6, position.CharacterX); position.FromNonSpaceCharCount(3); Assert.AreEqual(11, position.CharacterX); position.FromNonSpaceCharCount(5); Assert.AreEqual(17, position.CharacterX); }
//[Test] public void TestCharPosition14() { // Test the additional zero-length line beyond the last line. TextBuffer textBuffer = new TextBuffer("\thello\n"); coordinates = new CharPosition(textBuffer); // Test out clicking on the bottom-right corner of invalid area. coordinates.SetCharacterPosition(new System.Drawing.Point(300, 5)); Assert.AreEqual(0, coordinates.GetCharacterPosition().X); Assert.AreEqual(1, coordinates.GetCharacterPosition().Y); }
public System.Windows.Point TranslateToScreenPoint(System.Drawing.Point charPosition) { IScriptObject activeScript = Solution.Current.ActiveScript; CharPosition position = activeScript.CreateCharPosition(); position.SetCharacterPosition(charPosition.X, charPosition.Y); System.Windows.Point result = position.GetScreenPosition(); // The screen position needs offset based on the current scroll position. result.Offset(-scrollViewer.HorizontalOffset, -scrollViewer.VerticalOffset); return(result); }
/// <summary> /// Method to retrieve AutoComplete list and bind it to visual element /// </summary> private void DoAutoComplete(string variable) { Logger.LogInfo("DoAutoComplete", variable); EnsureAutoCompleteListCreated(); IScriptObject activeScript = Solution.Current.ActiveScript; string filePath = activeScript.GetParsedScript().GetScriptPath(); if (filePath == string.Empty) { filePath = null; } int[] linesToExclude = new int[] { textCore.CursorPosition.Y }; ITextBuffer textBuffer = textCore.CurrentTextBuffer; string partialContent = textBuffer.GetPartialContent(linesToExclude, " \n"); if (null == AutoCompletionHelper.MessageHandler) { AutoCompletionHelper.MessageHandler = new AutoCompleteMessageHandler(textEditorControl); } // Clear output stream messages before attempting another compilation. AutoCompleteMessageHandler messageHandler = null; messageHandler = AutoCompletionHelper.MessageHandler as AutoCompleteMessageHandler; messageHandler.ClearMessages(); AutoCompletionHelper.SetSearchPaths(ExtensionFactory.GetSearchPaths()); // Method to contact IDECodeGen.dll to retrieve the list for AutoComplete items List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list = AutoCompletionHelper.GetList(textCore.CursorPosition.Y, textCore.CursorPosition.X, partialContent, variable, filePath); messageHandler.DisplayPossibleErrors(); if (list.Count == 0) { return; } CharPosition position = activeScript.CreateCharPosition(); position.SetCharacterPosition(textCore.CursorPosition.X, textCore.CursorPosition.Y); // Add each AutoComplete Item one at a time Keyboard.Focus(textEditorCanvas); autoCompleteList.ClearList(); autoCompleteList.AddItemsToList(list); autoCompletePopup.Placement = PlacementMode.Custom; autoCompletePopup.PlacementTarget = textEditorCanvas; autoCompletePopup.CursorPosition = textCore.CursorPosition; autoCompletePopup.IsOpen = true; // The focus shift is important as the AutoCompleteList will // be re-routing events back to the main control now. autoCompleteList.DoFocusOnFirstItem(); autoCompletePopup.Width = autoCompleteList.Width; autoCompletePopup.Height = autoCompleteList.Height; }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { caretRect.Height = Configurations.FontDisplayHeight; if (null == drawingVisual) { drawingVisual = new DrawingVisual(); PauseCaretTimer(false); // Get timer going! } // There's no script yet. if (null == this.currentScript) { return(drawingVisual); } DrawingContext context = drawingVisual.RenderOpen(); CodeFragment[] crossHighlight = textEditorCanvas.TextEditorCore.GetCrossHighlightArray(); if (crossHighlight != null) { if (crossHighlight.Length != 0) { List <Rect> rectList = new List <Rect>(); foreach (CodeFragment codeFragment in crossHighlight) { CharPosition start = currentScript.CreateCharPosition(); start.SetCharacterPosition(codeFragment.ColStart, codeFragment.Line); CharPosition end = currentScript.CreateCharPosition(); end.SetCharacterPosition(codeFragment.ColEnd + 1, codeFragment.Line); List <Rect> tempList = CalculateRectangles(start, end, renderParams.firstVisibleLine); if (tempList != null) { rectList.AddRange(tempList); } } //SolidColorBrush crossHighlightBrush = new SolidColorBrush(Color.FromRgb(226, 230, 214)); RenderRectangles(context, rectList, UIColors.CrossHighlightColor); } } // We don't care about keyboard focus when in playback mode. if (false == TextEditorControl.Instance.IsInPlaybackMode) { // If the focus is not within the canvas, or on any extension popup, // then there's no need to show the caret (focus is probably other app). if (false == TextEditorControl.Instance.ShouldDisplayCaret()) { caretVisibility = System.Windows.Visibility.Hidden; } } // Cursor rendering pass... if (caretVisibility == System.Windows.Visibility.Visible) { System.Windows.Rect displayRect = caretRect; double firstVisibleColumn = textEditorCanvas.FirstVisibleColumn * Configurations.FormatFontWidth; displayRect.Offset(-firstVisibleColumn, -renderParams.firstVisibleLine * Configurations.FontDisplayHeight); context.DrawRectangle(Brushes.Black, null, displayRect); } context.Close(); return(drawingVisual); }
public void TestCharPositionToNonSpaceCharCount() { // \tb = a + 3; // \t c\t = a + \t b; TextBuffer textBuffer = new TextBuffer("\tb = a + 3;\n\t c\t = a + \t b;"); CharPosition position = new CharPosition(textBuffer); position.SetCharacterPosition(0, 0); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(1, 0); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(2, 0); Assert.AreEqual(1, position.ToNonSpaceCharCount()); position.SetCharacterPosition(8, 0); Assert.AreEqual(4, position.ToNonSpaceCharCount()); position.SetCharacterPosition(0, 1); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(5, 1); Assert.AreEqual(0, position.ToNonSpaceCharCount()); position.SetCharacterPosition(6, 1); Assert.AreEqual(1, position.ToNonSpaceCharCount()); position.SetCharacterPosition(17, 1); Assert.AreEqual(5, position.ToNonSpaceCharCount()); }
public void TestCharPositionFromNonSpaceCharCount() { // \tb = a + 3; // \t c\t = a + \t b; TextBuffer textBuffer = new TextBuffer("\tb = a + 3;\n\t c\t = a + \t b;"); CharPosition position = new CharPosition(textBuffer); position.SetCharacterPosition(0, 0); // First line. position.FromNonSpaceCharCount(1); Assert.AreEqual(2, position.CharacterX); position.FromNonSpaceCharCount(4); Assert.AreEqual(8, position.CharacterX); position.SetCharacterPosition(0, 1); // Second line. position.FromNonSpaceCharCount(1); Assert.AreEqual(6, position.CharacterX); position.FromNonSpaceCharCount(3); Assert.AreEqual(11, position.CharacterX); position.FromNonSpaceCharCount(5); Assert.AreEqual(17, position.CharacterX); }
public void TestCharPosition14() { // Test the additional zero-length line beyond the last line. TextBuffer textBuffer = new TextBuffer("\thello\n"); coordinates = new CharPosition(textBuffer); // Test out clicking on the bottom-right corner of invalid area. coordinates.SetCharacterPosition(new System.Drawing.Point(300, 5)); Assert.AreEqual(0, coordinates.GetCharacterPosition().X); Assert.AreEqual(1, coordinates.GetCharacterPosition().Y); }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { if (null == drawingVisual) { drawingVisual = new DrawingVisual(); } // There's no script yet. if (null == currentScript) { return(drawingVisual); } if (null == textEditorCanvas.TextEditorCore.CurrentTextBuffer) { return(drawingVisual); } DrawingContext context = drawingVisual.RenderOpen(); lineSelection.SetCharacterPosition(textEditorCanvas.TextEditorCore.CursorPosition); Rect cursorSelections = CalculateRectangleFullLine(lineSelection, renderParams.firstVisibleLine); RenderRectangle(context, cursorSelections, UIColors.CursorSelectionColor); List <InlineMessageItem> messageList = Solution.Current.GetInlineMessage(); if (messageList != null) { foreach (InlineMessageItem message in messageList) { int line = message.Line; int column = message.Column; if (Solution.Current.ActiveScript == null || message.FilePath != Solution.Current.ActiveScript.GetParsedScript().GetScriptPath()) { continue; } if (line >= 0) { System.Drawing.Point inlineSelectionStart = new System.Drawing.Point(column, line); inLineSelection.SetCharacterPosition(inlineSelectionStart); Rect outputSelections = CalculateRectangleFullLine(inLineSelection, renderParams.firstVisibleLine); Color inLineColor = new Color(); switch (message.Type) { case InlineMessageItem.OutputMessageType.Error: inLineColor = UIColors.InlinErrorColor; break; case InlineMessageItem.OutputMessageType.Warning: inLineColor = UIColors.InlineWarningColor; break; case InlineMessageItem.OutputMessageType.PossibleError: inLineColor = UIColors.InlinPossibleErrorColor; break; case InlineMessageItem.OutputMessageType.PossibleWarning: inLineColor = UIColors.InlinPossibleWarningColor; break; } RenderRectangle(context, outputSelections, inLineColor); } } } if (null != breakpointsRef) { CharPosition startPoint = currentScript.CreateCharPosition(); CharPosition endPoint = currentScript.CreateCharPosition(); foreach (CodeRange breakpoint in breakpointsRef) { if (FallsWithinActiveScript(breakpoint.StartInclusive) == false) { continue; // This breakpoint does not belong to the script. } int startX = breakpoint.StartInclusive.CharNo - 1; int startY = breakpoint.StartInclusive.LineNo - 1; int endX = breakpoint.EndExclusive.CharNo - 1; int endY = breakpoint.EndExclusive.LineNo - 1; startPoint.SetCharacterPosition(startX, startY); endPoint.SetCharacterPosition(endX, endY); Rect region = CalculateRectangleFullLine(startPoint, renderParams.firstVisibleLine); RenderRectangle(context, region, UIColors.BreakpointLineColor); } } if (FallsWithinActiveScript(executionCursor.StartInclusive)) { CharPosition start = currentScript.CreateCharPosition(); CharPosition end = currentScript.CreateCharPosition(); start.SetCharacterPosition( executionCursor.StartInclusive.CharNo - 1, executionCursor.StartInclusive.LineNo - 1); end.SetCharacterPosition( executionCursor.EndExclusive.CharNo - 1, executionCursor.EndExclusive.LineNo - 1); List <Rect> execCursors = CalculateRectangles(start, end, renderParams.firstVisibleLine); RenderRectangles(context, execCursors, UIColors.ExecutionCursorColor); } List <Rect> selections = CalculateRectangles(selectionStart, selectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, selections, UIColors.SelectionsColor); List <FindPosition> searchResults = textEditorCanvas.TextEditorCore.CurrentTextBuffer.SearchResult; if (searchResults != null) { System.Drawing.Point start; System.Drawing.Point end; foreach (FindPosition item in searchResults) { start = item.startPoint; end = item.endPoint; end.X += 1; allOccurencesSelectionStart.SetCharacterPosition(start); allOccurencesSelectionEnd.SetCharacterPosition(end); List <Rect> findSelections = CalculateRectangles(allOccurencesSelectionStart, allOccurencesSelectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, findSelections, Colors.Yellow); } int searchIndex = textEditorCanvas.TextEditorCore.CurrentTextBuffer.CurrentSearchIndex; if (searchResults.Count != 0 && searchIndex != -1) { FindPosition currentPosition = searchResults[searchIndex]; System.Drawing.Point startPoint = currentPosition.startPoint; System.Drawing.Point endPoint = currentPosition.endPoint; endPoint.X += 1; if (startPoint.X == 0 && endPoint.X == 0 && startPoint.Y == 0 && endPoint.Y == 0) { } else { currentOccurenceSelectionStart.SetCharacterPosition(startPoint); currentOccurenceSelectionEnd.SetCharacterPosition(endPoint); List <Rect> currentOccurenceSelections = CalculateRectangles(currentOccurenceSelectionStart, currentOccurenceSelectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, currentOccurenceSelections, Colors.Orange); } } } context.Close(); return(drawingVisual); }
public void ResetHighlightLayer() { selectionStart.SetCharacterPosition(0, 0); selectionEnd.SetCharacterPosition(0, 0); }