コード例 #1
0
ファイル: view.go プロジェクト: kisielk/vigo
// Filter _must_ return a new slice and shouldn't touch contents of the
// argument, perfect filter examples are: bytes.Title, bytes.ToUpper,
// bytes.ToLower
func (v *View) filterText(from, to buffer.Cursor, filter func([]byte) []byte) {
	c1, c2 := buffer.SortCursors(from, to)
	d := c1.Distance(c2)
	v.buf.Delete(c1, d)
	data := filter(v.buf.History.LastAction().Data)
	v.buf.Insert(c1, data)
}
コード例 #2
0
ファイル: view.go プロジェクト: kisielk/vigo
func (s Selection) includes(c buffer.Cursor) bool {
	if s.Type == SelectionNone {
		return false
	}

	start, end := buffer.SortCursors(s.Start, s.End)
	inc := false

	switch s.Type {
	case SelectionChar:
		inc = (start.Before(c) || start.Equals(c)) && (c.Before(end) || c.Equals(end))
	case SelectionLine:
		inc = start.LineNum <= c.LineNum && c.LineNum <= end.LineNum
	case SelectionBlock:
		// TODO
		panic("not implemented")
	}

	return inc
}
コード例 #3
0
ファイル: view.go プロジェクト: kisielk/vigo
func (s Selection) EffectiveRange() (r buffer.Range) {
	r.Start, r.End = buffer.SortCursors(s.Start, s.End)
	switch s.Type {
	case SelectionChar:
		// Inclusive -> exclusive range
		r.End.NextRune(true)
	case SelectionLine:
		// Delete from the beginning of first line to the start of line after last.
		r.Start.Boffset = 0
		r.End.NextLine()
		// XXX NextLine() sets Boffset to -1 which doesn't work for us,
		// but gets specially handled in view.MoveCursorTo
		r.End.Boffset = 0
	case SelectionBlock:
		// TODO Return a list of effective ranges. This will also work
		// if we have sparse selection such as in Sublime Text
		panic("not implemented")
	}
	return
}