override public void Redo() { eraseCommand.Redo(); int lastILine = -1; foreach (Selection selection in selections) { Place place = lines.PlaceOf(selection.caret); if (place.iLine == lastILine) { continue; } lastILine = place.iLine; if (place.iLine > 0) { Line line = lines[place.iLine]; if (line.NormalCount > 0 && line.IsOnlySpaces()) { Line prevLine = lines[place.iLine - 1]; int iChar; int prevSpacesSize = prevLine.GetFirstSpaceSize(out iChar); if (prevSpacesSize % lines.tabSize == 0) { int spacesSize = line.GetFirstSpaceSize(out iChar); char lastPrevNotSpace = prevLine.GetLastNotSpace(); if (lastPrevNotSpace != '{' && prevSpacesSize == spacesSize) { int newPos = spacesSize - lines.tabSize; int newIChar = line.IndexOfPos(newPos); int newPos2 = line.PosOfIndex(newIChar); if (newPos2 == newPos) { selection.anchor += newIChar - place.iChar; } } else if (lastPrevNotSpace == '{' && prevSpacesSize == spacesSize - lines.tabSize) { int newPos = prevSpacesSize; int newIChar = line.IndexOfPos(newPos); int newPos2 = line.PosOfIndex(newIChar); if (newPos2 == newPos) { selection.anchor += newIChar - place.iChar; } } } } } } insertText = new InsertTextCommand("}", null, true); insertText.lines = lines; insertText.selections = selections; insertText.Init(); insertText.Redo(); }
override public void Redo() { lines.ResizeSelections(ranges.Count); string[] lineBreaks = new string[selections.Count]; for (int i = ranges.Count; i-- > 0;) { SimpleRange range = ranges[i]; Line endLine = lines[range.index + range.count - 1]; Selection selection = selections[i]; lineBreaks[i] = range.index + range.count == lines.LinesCount ? "" : lines.lineBreak; selection.anchor = lines.IndexOf(new Place(0, range.index)); selection.caret = lines.IndexOf(new Place(endLine.charsCount, range.index + range.count - 1)); } this.eraseCommand = null; this.indentCommand = null; InsertTextCommand eraseCommand = new InsertTextCommand(null, lineBreaks, true); eraseCommand.lines = lines; eraseCommand.selections = selections; if (eraseCommand.Init()) { string[] indents = new string[selections.Count]; for (int i = 0; i < selections.Count; i++) { Selection selection = selections[i]; Place place = lines.PlaceOf(Math.Min(selection.anchor, selection.caret)); Line line = lines[place.iLine]; string text; int count; line.GetFirstIntegerTabs(out text, out count); indents[i] = text ?? ""; } eraseCommand.Redo(); for (int i = 0; i < selections.Count; i++) { Selection selection = selections[i]; selection.anchor = selection.caret = selection.caret - lineBreaks[i].Length; } this.eraseCommand = eraseCommand; InsertTextCommand indentCommand = new InsertTextCommand(null, indents, true); indentCommand.lines = lines; indentCommand.selections = selections; if (indentCommand.Init()) { indentCommand.Redo(); this.indentCommand = indentCommand; } } }
override public void Redo() { eraseCommand.Redo(); int lastILine = -1; string[] texts = new string[selections.Count]; for (int i = 0; i < selections.Count; ++i) { Selection selection = selections[i]; texts[i] = ""; Place place = lines.PlaceOf(selection.caret); if (place.iLine == lastILine) { continue; } lastILine = place.iLine; if (place.iLine + 1 < lines.LinesCount) { Line line = lines[place.iLine]; if (line.NormalCount > 0 && line.IsOnlySpaces()) { Line nextLine = lines[place.iLine + 1]; int iChar; int nextSpacesSize = nextLine.GetFirstSpaceSize(out iChar); if (nextSpacesSize > 0 && nextSpacesSize % lines.tabSize == 0) { int spacesSize = line.GetFirstSpaceSize(out iChar); char nextPrevNotSpace = nextLine.GetLastNotSpace(); if (nextPrevNotSpace == '}' && nextSpacesSize == spacesSize) { texts[i] = lines.TabSettings.Tab; } } } } } insertText = new InsertTextCommand(null, texts, true); insertText.lines = lines; insertText.selections = selections; insertText.Init(); insertText.Redo(); }