Exemplo n.º 1
0
// DecreaseIndent decreases indent of lines that fall within selection by 1 tab (for lines where it's possible).
func (cp *CaretPosition) DecreaseIndent() {
	selStart, selEnd := cp.SelectionRange2()
	first, last := cp.lineIndexSpan()

	newContent := cp.w.Content()[:cp.w.Line(first).Start()]
	for lineIndex := first; lineIndex <= last; lineIndex++ {
		contentLine := cp.w.Line(lineIndex)

		if lineIndex != first {
			newContent += "\n"
		}
		line := cp.w.Content()[contentLine.Start():contentLine.End()]
		if strings.HasPrefix(line, "\t") {
			line = line[1:] // Trim leading tab.

			if lineIndex == first {
				selStart.Move(-1)
			}
			if lineIndex == last {
				selEnd.Move(-1)
			}
		}
		newContent += line
	}
	newContent += cp.w.Content()[cp.w.Line(last).End():]

	gist7802150.SetViewGroup(cp.w, newContent)
}
Exemplo n.º 2
0
// IncreaseIndent increases indent of all lines that fall within selection by 1 tab.
func (cp *CaretPosition) IncreaseIndent() {
	selStart, selEnd := cp.SelectionRange2()
	first, last := cp.lineIndexSpan()

	newContent := cp.w.Content()[:cp.w.Line(first).Start()]
	for lineIndex := first; lineIndex <= last; lineIndex++ {
		contentLine := cp.w.Line(lineIndex)

		if lineIndex != first {
			newContent += "\n"
		}
		newContent += "\t" + cp.w.Content()[contentLine.Start():contentLine.End()]
	}
	newContent += cp.w.Content()[cp.w.Line(last).End():]

	gist7802150.SetViewGroup(cp.w, newContent)

	// Safe to use willMoveH after SetViewGroup, since we know each line will always get a character longer.
	selStart.willMoveH(1)
	selEnd.willMoveH(1)
}
Exemplo n.º 3
0
// Replaces selection with string s and moves caret to end of s.
func (cp *CaretPosition) ReplaceSelectionWith(s string) {
	selStart, selEnd := cp.SelectionRange2()
	gist7802150.SetViewGroup(cp.w, cp.w.Content()[:selStart.Logical()]+s+cp.w.Content()[selEnd.Logical():])
	selStart.willMoveH(int32(len(s)))
	selEnd.MoveTo(selStart)
}