public void Delete() { Logger.GetInstance().Debug("Delete() >>"); try { _innerTextbox.ClearSelected(); } catch (Exception e) { throw e; } Logger.GetInstance().Debug("<< Delete()"); }
/// <summary> /// Cut selected text into Clipboard /// </summary> public static void Cut(FastColoredTextBox textbox) { if (!textbox.Selection.IsEmpty) { EditorCommands.Copy(textbox); textbox.ClearSelected(); } else if (textbox.LinesCount == 1) { textbox.Selection.SelectAll(); EditorCommands.Copy(textbox); textbox.ClearSelected(); } else { EditorCommands.Copy(textbox); //remove current line if (textbox.Selection.Start.iLine >= 0 && textbox.Selection.Start.iLine < textbox.LinesCount) { int iLine = textbox.Selection.Start.iLine; textbox.RemoveLines(new List<int> { iLine }); textbox.Selection.Start = new Place(0, Math.Max(0, Math.Min(iLine, textbox.LinesCount - 1))); } } }
private static void DropFromTheInside(FastColoredTextBox textbox, Place place, string text) { Range insertRange = new Range(textbox, place, place); // Determine, if the dragged string should be copied or moved bool copyMode = (textbox.draggedRange == null) || // drag from outside (textbox.draggedRange.ReadOnly) || // dragged range is read only ((Control.ModifierKeys & Keys.Control) != Keys.None); if (!textbox.draggedRange.Contains(place)) { textbox.BeginAutoUndo(); textbox.Selection.BeginUpdate(); //remember dragged selection for undo/redo textbox.Selection = textbox.draggedRange; textbox.lines.Manager.ExecuteCommand(new SelectCommand(textbox.lines)); // if (textbox.draggedRange.ColumnSelectionMode) { // dropping a block selection, add a few new lines textbox.draggedRange.Normalize(); var endLine = place.iLine + textbox.draggedRange.End.iLine - textbox.draggedRange.Start.iLine; var end = new Place(place.iChar,endLine ); insertRange = new Range(textbox, place, end) { ColumnSelectionMode = true }; for (int i = textbox.LinesCount; i <= insertRange.End.iLine; i++) { textbox.Selection.GoLast(false); textbox.InsertChar('\n'); } } if (!insertRange.ReadOnly) { if (place < textbox.draggedRange.Start) { // Target place is before the dragged range, // first delete dragged range if not in copy mode if (copyMode == false) { textbox.Selection = textbox.draggedRange; textbox.ClearSelected(); // clear original selectin } // Insert text textbox.Selection = insertRange; textbox.Selection.ColumnSelectionMode = insertRange.ColumnSelectionMode; textbox.InsertText(text); } else { // Target place is after the dragged range, first insert the text // Insert text textbox.Selection = insertRange; textbox.Selection.ColumnSelectionMode = insertRange.ColumnSelectionMode; textbox.InsertText(text); // Delete dragged range if not in copy mode if (copyMode == false) { textbox.Selection = textbox.draggedRange; textbox.ClearSelected(); } } } // Selection start and end position Place startPosition = place; Place endPosition = textbox.Selection.Start; // Correct selection Range dR = (textbox.draggedRange.End > textbox.draggedRange.Start) // dragged selection ? RangeUtil.GetRange(textbox, textbox.draggedRange.Start, textbox.draggedRange.End) : RangeUtil.GetRange(textbox, textbox.draggedRange.End, textbox.draggedRange.Start); Place tP = place; // targetPlace int tS_S_Line; // targetSelection.Start.iLine int tS_S_Char; // targetSelection.Start.iChar int tS_E_Line; // targetSelection.End.iLine int tS_E_Char; // targetSelection.End.iChar if ((place > textbox.draggedRange.Start) && (copyMode == false)) { if (textbox.draggedRange.ColumnSelectionMode == false) { // Normal selection mode: // Determine character/column position of target selection if (dR.Start.iLine != dR.End.iLine) // If more then one line was selected/dragged ... { tS_S_Char = (dR.End.iLine != tP.iLine) ? tP.iChar : dR.Start.iChar + (tP.iChar - dR.End.iChar); tS_E_Char = dR.End.iChar; } else // only one line was selected/dragged { if (dR.End.iLine == tP.iLine) { tS_S_Char = tP.iChar - dR.Text.Length; tS_E_Char = tP.iChar; } else { tS_S_Char = tP.iChar; tS_E_Char = tP.iChar + dR.Text.Length; } } // Determine line/row of target selection if (dR.End.iLine != tP.iLine) { tS_S_Line = tP.iLine - (dR.End.iLine - dR.Start.iLine); tS_E_Line = tP.iLine; } else { tS_S_Line = dR.Start.iLine; tS_E_Line = dR.End.iLine; } startPosition = new Place(tS_S_Char, tS_S_Line); endPosition = new Place(tS_E_Char, tS_E_Line); } } // Select inserted text if (!textbox.draggedRange.ColumnSelectionMode) { textbox.Selection = new Range(textbox, startPosition, endPosition); } else { if ((copyMode == false) && (place.iLine >= dR.Start.iLine) && (place.iLine <= dR.End.iLine) && (place.iChar >= dR.End.iChar)) { tS_S_Char = tP.iChar - (dR.End.iChar - dR.Start.iChar); tS_E_Char = tP.iChar; } else { tS_S_Char = tP.iChar; tS_E_Char = tP.iChar + (dR.End.iChar - dR.Start.iChar); } tS_S_Line = tP.iLine; tS_E_Line = tP.iLine + (dR.End.iLine - dR.Start.iLine); startPosition = new Place(tS_S_Char, tS_S_Line); endPosition = new Place(tS_E_Char, tS_E_Line); textbox.Selection = new Range(textbox, startPosition, endPosition) { ColumnSelectionMode = true }; } textbox.Range.EndUpdate(); textbox.EndAutoUndo(); } textbox.Selection.Inverse(); }
private void Split(int iLine, FastColoredTextBox tb, string s) { string[] sep = s.Split(':'); tb.Selection.Start = new Place(0, iLine); tb.Selection.Expand(); string seperator; if (sep.Length == 3 && sep[1] == string.Empty) seperator = ":"; else seperator = sep[1]; var lines = tb.SelectedText.Split(seperator.ToCharArray()); tb.ClearSelected(); foreach (string line in lines) { tb.InsertText(line+"\n"); } tb.ClearCurrentLine(); }