예제 #1
0
파일: textbox.go 프로젝트: langxj/gxui
func (t *TextBox) DoubleClick(ev gxui.MouseEvent) (consume bool) {
	if p, ok := t.RuneIndexAt(ev.Point); ok {
		s, e := t.controller.WordAt(p)
		if ev.Modifier&gxui.ModControl != 0 {
			t.controller.AddSelection(gxui.CreateTextSelection(s, e, false))
		} else {
			t.controller.SetSelection(gxui.CreateTextSelection(s, e, false))
		}
	}
	t.InputEventHandler.DoubleClick(ev)
	return true
}
예제 #2
0
파일: code_editor.go 프로젝트: langxj/gxui
func (t *CodeEditor) KeyPress(ev gxui.KeyboardEvent) (consume bool) {
	switch ev.Key {
	case gxui.KeyTab:
		replace := true
		for _, sel := range t.controller.Selections() {
			s, e := sel.Range()
			if t.controller.LineIndex(s) != t.controller.LineIndex(e) {
				replace = false
				break
			}
		}
		switch {
		case replace:
			t.controller.ReplaceAll(strings.Repeat(" ", t.tabWidth))
			t.controller.Deselect(false)
		case ev.Modifier.Shift():
			t.controller.UnindentSelection(t.tabWidth)
		default:
			t.controller.IndentSelection(t.tabWidth)
		}
		return true
	case gxui.KeySpace:
		if ev.Modifier.Control() {
			t.ShowSuggestionList()
			return
		}
	case gxui.KeyUp:
		fallthrough
	case gxui.KeyDown:
		if t.IsSuggestionListShowing() {
			return t.suggestionList.KeyPress(ev)
		}
	case gxui.KeyLeft:
		t.HideSuggestionList()
	case gxui.KeyRight:
		t.HideSuggestionList()
	case gxui.KeyEnter:
		controller := t.controller
		if t.IsSuggestionListShowing() {
			text := t.suggestionAdapter.Suggestion(t.suggestionList.Selected()).Code()
			s, e := controller.WordAt(t.controller.LastCaret())
			controller.SetSelection(gxui.CreateTextSelection(s, e, false))
			controller.ReplaceAll(text)
			controller.Deselect(false)
			t.HideSuggestionList()
		} else {
			t.controller.ReplaceWithNewlineKeepIndent()
		}
		return true
	case gxui.KeyEscape:
		if t.IsSuggestionListShowing() {
			t.HideSuggestionList()
			return true
		}
	}
	return t.TextBox.KeyPress(ev)
}
예제 #3
0
파일: textbox.go 프로젝트: langxj/gxui
func (t *TextBox) lineMouseDown(line TextBoxLine, ev gxui.MouseEvent) {
	if ev.Button == gxui.MouseButtonLeft {
		p := line.RuneIndexAt(ev.Point)
		t.selectionDragging = true
		t.selectionDrag = gxui.CreateTextSelection(p, p, false)
		if !ev.Modifier.Control() {
			t.controller.SetCaret(p)
		}
	}
}
예제 #4
0
파일: textbox.go 프로젝트: langxj/gxui
func (t *TextBox) MouseMove(ev gxui.MouseEvent) {
	t.List.MouseMove(ev)
	if t.selectionDragging {
		if p, ok := t.RuneIndexAt(ev.Point); ok {
			t.selectionDrag = gxui.CreateTextSelection(t.selectionDrag.From(), p, false)
			t.selectionDragging = true
			t.onRedrawLines.Fire()
		}
	}
}
예제 #5
0
func (t *DefaultTextBoxLine) PaintSelections(c gxui.Canvas) {
	controller := t.textbox.controller

	ls, le := controller.LineStart(t.lineIndex), controller.LineEnd(t.lineIndex)

	selections := controller.Selections()
	if t.textbox.selectionDragging {
		interval.Replace(&selections, t.textbox.selectionDrag)
	}
	interval.Visit(&selections, gxui.CreateTextSelection(ls, le, false), func(s, e uint64, _ int) {
		if s < e {
			x := t.outer.MeasureRunes(ls, int(s)).W
			m := t.outer.MeasureRunes(int(s), int(e))
			top := math.Point{X: t.caretWidth + x, Y: 0}
			bottom := top.Add(m.Point())
			t.outer.PaintSelection(c, top, bottom)
		}
	})
}