key_bind_func.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package prompt
  2. // GoLineEnd Go to the End of the line
  3. func GoLineEnd(buf *Buffer) {
  4. x := []rune(buf.Document().TextAfterCursor())
  5. buf.CursorRight(len(x))
  6. }
  7. // GoLineBeginning Go to the beginning of the line
  8. func GoLineBeginning(buf *Buffer) {
  9. x := []rune(buf.Document().TextBeforeCursor())
  10. buf.CursorLeft(len(x))
  11. }
  12. // DeleteChar Delete character under the cursor
  13. func DeleteChar(buf *Buffer) {
  14. buf.Delete(1)
  15. }
  16. // DeleteWord Delete word before the cursor
  17. func DeleteWord(buf *Buffer) {
  18. buf.DeleteBeforeCursor(len([]rune(buf.Document().TextBeforeCursor())) - buf.Document().FindStartOfPreviousWordWithSpace())
  19. }
  20. // DeleteBeforeChar Go to Backspace
  21. func DeleteBeforeChar(buf *Buffer) {
  22. buf.DeleteBeforeCursor(1)
  23. }
  24. // GoRightChar Forward one character
  25. func GoRightChar(buf *Buffer) {
  26. buf.CursorRight(1)
  27. }
  28. // GoLeftChar Backward one character
  29. func GoLeftChar(buf *Buffer) {
  30. buf.CursorLeft(1)
  31. }
  32. // GoRightWord Forward one word
  33. func GoRightWord(buf *Buffer) {
  34. buf.CursorRight(buf.Document().FindEndOfCurrentWordWithSpace())
  35. }
  36. // GoLeftWord Backward one word
  37. func GoLeftWord(buf *Buffer) {
  38. buf.CursorLeft(len([]rune(buf.Document().TextBeforeCursor())) - buf.Document().FindStartOfPreviousWordWithSpace())
  39. }