Example #1
0
func (t *TextBoxController) AddCarets(transform SelectionTransform) {
	t.storeCaretLocationsNextEdit = true
	up := t.selections.Transform(0, transform)
	for _, s := range up {
		interval.Merge(&t.selections, s)
	}
	t.onSelectionChanged.Fire()
}
Example #2
0
func TestTextSelectionMergeExtendEnd(t *testing.T) {
	s1 := TextSelection{6, 9, true}
	s2 := TextSelection{8, 15, false}
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		TextSelection{6, 15, false},
	}, l)
}
Example #3
0
func TestTextSelectionMergeDuplicate0Len(t *testing.T) {
	s1 := TextSelection{2, 2, false}
	s2 := TextSelection{2, 2, true}
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		TextSelection{2, 2, true},
	}, l)
}
Example #4
0
func TestTextSelectionMergeEncompass(t *testing.T) {
	s1 := TextSelection{6, 9, false}
	s2 := TextSelection{5, 10, true}
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		TextSelection{5, 10, true},
	}, l)
}
Example #5
0
func TestTextSelectionMergeAtStart(t *testing.T) {
	s1 := TextSelection{6, 9, true}
	s2 := TextSelection{6, 7, false}
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		TextSelection{6, 9, false},
	}, l)
}
Example #6
0
func (l TextSelectionList) Transform(from int, transform func(i int) int) TextSelectionList {
	res := TextSelectionList{}
	for _, s := range l {
		start := s.start
		end := s.end
		if start >= from {
			start = transform(start)
		}
		if end >= from {
			end = transform(end)
		}
		interval.Merge(&res, TextSelection{start, end, s.caretAtStart})
	}
	return res
}
Example #7
0
func (l TextSelectionList) TransformCarets(from int, transform func(i int) int) TextSelectionList {
	res := TextSelectionList{}
	for _, s := range l {
		if s.caretAtStart && s.start >= from {
			s.start = transform(s.start)
		} else if s.end >= from {
			s.end = transform(s.end)
		}
		if s.start > s.end {
			tmp := s.start
			s.start = s.end
			s.end = tmp
			s.caretAtStart = !s.caretAtStart
		}
		interval.Merge(&res, s)
	}
	return res
}
Example #8
0
func (t *TextBoxController) updateSelectionsForEdits(edits []TextBoxEdit) {
	min := 0
	max := len(t.text)
	selections := TextSelectionList{}
	for _, selection := range t.selections {
		for _, e := range edits {
			at := e.At
			delta := e.Delta
			if selection.start > at {
				selection.start += delta
			}
			if selection.end >= at {
				selection.end += delta
			}
		}
		if selection.end < selection.start {
			selection.end = selection.start
		}
		selection.start = math.Clamp(selection.start, min, max)
		selection.end = math.Clamp(selection.end, min, max)
		interval.Merge(&selections, selection)
	}
	t.selections = selections
}
Example #9
0
func TestTextSelectionMergeOne(t *testing.T) {
	s := TextSelection{5, 10, true}
	l := TextSelectionList{}
	interval.Merge(&l, s)
	test.AssertEquals(t, TextSelectionList{s}, l)
}
Example #10
0
func (t *TextBoxController) AddSelection(s TextSelection) {
	t.storeCaretLocationsNextEdit = true
	interval.Merge(&t.selections, s)
	t.onSelectionChanged.Fire()
}