go-to-line.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. backgroundColor: 'var(--bg-secondary-themed)',
  27. '& label': {
  28. margin: 0,
  29. fontSize: '14px',
  30. color: 'var(--content-primary-themed)',
  31. '& .cm-textfield': {
  32. margin: '0 10px',
  33. maxWidth: '100px',
  34. height: '34px',
  35. padding: '5px 16px',
  36. fontSize: '14px',
  37. fontWeight: 'normal',
  38. color: 'var(--content-primary-themed)',
  39. backgroundColor: 'var(--bg-primary-themed)',
  40. border: '1px solid var(--border-primary-themed)',
  41. backgroundImage: 'none',
  42. borderRadius: 'var(--border-radius-base)',
  43. boxShadow: 'inset 0 1px 1px rgb(0 0 0 / 8%)',
  44. transition:
  45. 'border-color ease-in-out .15s, box-shadow ease-in-out .15s',
  46. '&:focus-visible': {
  47. outline: 'none',
  48. boxShadow:
  49. 'inset 0 1px 1px rgb(0 0 0 / 8%), 0 0 8px rgb(102 175 233 / 60%)',
  50. },
  51. },
  52. },
  53. '& .cm-button': {
  54. padding: '4px 16px 5px',
  55. textTransform: 'capitalize',
  56. fontSize: '14px',
  57. userSelect: 'none',
  58. backgroundImage: 'none',
  59. backgroundColor: 'var(--bg-secondary-themed)',
  60. borderRadius: 'var(--border-radius-full)',
  61. border: '0 solid transparent',
  62. color: 'var(--content-primary-themed)',
  63. fontWeight: '600',
  64. transition: 'background-color ease-in-out .15s',
  65. '&:hover': {
  66. backgroundColor: 'var(--bg-tertiary-themed)',
  67. },
  68. },
  69. },
  70. })