go-to-line.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Prec } from '@codemirror/state'
  2. import { EditorView, keymap } from '@codemirror/view'
  3. import { gotoLine } from '@codemirror/search'
  4. /**
  5. * A custom extension that provides a keyboard shortcut
  6. * and panel with UI for jumping to a specific line number.
  7. */
  8. export const goToLinePanel = () => {
  9. return [
  10. Prec.high(
  11. keymap.of([
  12. {
  13. key: 'Mod-Shift-l',
  14. preventDefault: true,
  15. run: gotoLine,
  16. },
  17. ])
  18. ),
  19. EditorView.baseTheme({
  20. '.cm-panel.cm-gotoLine': {
  21. padding: '10px',
  22. fontSize: '14px',
  23. '& label': {
  24. margin: 0,
  25. fontSize: '14px',
  26. '& .cm-textfield': {
  27. margin: '0 10px',
  28. maxWidth: '100px',
  29. height: '34px',
  30. padding: '5px 16px',
  31. fontSize: '14px',
  32. fontWeight: 'normal',
  33. lineHeight: 'var(--line-height-base)',
  34. color: 'var(--input-color)',
  35. backgroundColor: '#fff',
  36. backgroundImage: 'none',
  37. borderRadius: 'var(--input-border-radius)',
  38. boxShadow: 'inset 0 1px 1px rgb(0 0 0 / 8%)',
  39. transition:
  40. 'border-color ease-in-out .15s, box-shadow ease-in-out .15s',
  41. '&:focus-visible': {
  42. outline: 'none',
  43. },
  44. '&:focus': {
  45. borderColor: 'var(--input-border-focus)',
  46. },
  47. },
  48. },
  49. '& .cm-button': {
  50. padding: '4px 16px 5px',
  51. textTransform: 'capitalize',
  52. fontSize: '14px',
  53. lineHeight: 'var(--line-height-base)',
  54. userSelect: 'none',
  55. backgroundImage: 'none',
  56. backgroundColor: 'var(--btn-default-bg)',
  57. borderRadius: 'var(--btn-border-radius-base)',
  58. border: '0 solid transparent',
  59. color: '#fff',
  60. },
  61. },
  62. }),
  63. ]
  64. }