go-to-line.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. gotoLineTheme,
  20. ]
  21. }
  22. const gotoLineTheme = EditorView.baseTheme({
  23. '.cm-panel.cm-gotoLine': {
  24. padding: '10px',
  25. fontSize: '14px',
  26. '& label': {
  27. margin: 0,
  28. fontSize: '14px',
  29. '& .cm-textfield': {
  30. margin: '0 10px',
  31. maxWidth: '100px',
  32. height: '34px',
  33. padding: '5px 16px',
  34. fontSize: '14px',
  35. fontWeight: 'normal',
  36. lineHeight: 'var(--line-height-base)',
  37. color: 'var(--input-color)',
  38. backgroundColor: '#fff',
  39. backgroundImage: 'none',
  40. borderRadius: 'var(--input-border-radius)',
  41. boxShadow: 'inset 0 1px 1px rgb(0 0 0 / 8%)',
  42. transition:
  43. 'border-color ease-in-out .15s, box-shadow ease-in-out .15s',
  44. '&:focus-visible': {
  45. outline: 'none',
  46. },
  47. '&:focus': {
  48. borderColor: 'var(--input-border-focus)',
  49. },
  50. },
  51. },
  52. '& .cm-button': {
  53. padding: '4px 16px 5px',
  54. textTransform: 'capitalize',
  55. fontSize: '14px',
  56. lineHeight: 'var(--line-height-base)',
  57. userSelect: 'none',
  58. backgroundImage: 'none',
  59. backgroundColor: 'var(--btn-default-bg)',
  60. borderRadius: 'var(--btn-border-radius-base)',
  61. border: '0 solid transparent',
  62. color: '#fff',
  63. },
  64. },
  65. })