@chordproject/editor 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,21 @@
1
1
  # ChordPro Editor
2
2
 
3
- A CodeMirror 6 based editor for ChordPro songs. **~26 KB** (~7 KB gzipped).
3
+ A CodeMirror 6 editor for ChordPro songs, with syntax highlighting, completions, folding,
4
+ search and replace, and inline diagnostics.
4
5
 
5
6
  **Part of [ChordProject](https://chordproject.com/)**
6
7
 
7
8
  ## Overview
8
9
 
9
- A CodeMirror 6 editor that highlights ChordPro syntax (directives, chords, comments, tab blocks),
10
- aligned with the official
10
+ A standalone CodeMirror 6 editor that understands ChordPro directives, chords, comments, and tab
11
+ blocks. Its syntax support follows the official
11
12
  [ChordPro directives](https://www.chordpro.org/chordpro/chordpro-directives/) and
12
13
  [chord](https://www.chordpro.org/chordpro/chordpro-chords/) specification.
13
14
 
15
+ The editor also lints parser warnings, repeated single-value metadata, unclosed sections, and
16
+ valid but non-canonical chord spellings. Hosts can provide localized labels for diagnostics and
17
+ the search panel.
18
+
14
19
  ## Usage
15
20
 
16
21
  ### Requirements
@@ -49,6 +54,8 @@ standalone use. Ships with its own TypeScript types, no `@types/*` package neede
49
54
  | `extensions` | `Extension[]?` | Extra CodeMirror 6 extensions to append (escape hatch). |
50
55
  | `onChange` | `(value: string) => void` | Called with the full document on every change. |
51
56
  | `onFocus` / `onBlur` | `() => void` | Called when the editor gains/loses focus. |
57
+ | `searchLabels` | `() => SearchLabels` | Supplies translated labels for the search and replace panel. |
58
+ | `lintLabels` | `() => LintLabels` | Supplies translated labels for all inline diagnostics. |
52
59
 
53
60
  The returned `ChordProEditor` handle:
54
61
 
@@ -59,8 +66,10 @@ The returned `ChordProEditor` handle:
59
66
  | `setTheme('light' \| 'dark')` | Swaps the theme without recreating the editor. |
60
67
  | `insertChord()` | Inserts `"[]"` at the cursor (or wraps the selection) and opens chord suggestions - no keyboard shortcut needed, works from a button/tap. |
61
68
  | `openCompletionList()` | Opens the completion list (chords or snippets, depending on cursor position) without any keyboard shortcut. |
69
+ | `openSearch()` | Opens the search and replace panel. |
62
70
  | `getChordNotationSuggestions()` | Returns grouped suggestions for valid non-canonical chord spellings, such as `Asus` to `Asus4`. |
63
71
  | `normalizeChordNotation()` | Replaces all suggested spellings in one undoable CodeMirror transaction and returns the applied groups. |
72
+ | `refreshLint()` | Re-runs diagnostics, for example after changing the active language. |
64
73
  | `focus()` / `destroy()` | Focus the editor / tear it down and release its DOM node. |
65
74
 
66
75
  Multiple independent `createChordProEditor()` instances can coexist on the same page.
@@ -83,19 +92,35 @@ $ npm test
83
92
  The test suite covers grouped chord-notation suggestions and safe normalization of slash chords,
84
93
  annotations, already canonical chords, and historical combined tokens.
85
94
 
95
+ ## Publishing
96
+
97
+ Publishing uses npm Trusted Publishing from GitHub Actions; no npm token is stored in GitHub.
98
+ In npm package settings, add a GitHub Actions trusted publisher for organization `chordproject`,
99
+ repository `chordproject-editor`, and workflow file `publish.yml`. After merging changes, run
100
+ `npm run release` for a patch, or `npm run release:minor` / `npm run release:major`. These
101
+ commands run tests, bump the version, commit and tag it, then push; GitHub Actions publishes to
102
+ npmjs.org using OIDC. The tag must match `package.json`.
103
+
86
104
  ## Features
87
105
 
88
106
  - Syntax highlighting: directives (known/custom/invalid), chords, comments, tab blocks, `{define:}`
89
107
  - Chord autocomplete (common chord vocabulary, boosted by chords already used in the song)
90
108
  - Directive snippets, expandable with `Tab` (see table below)
91
109
  - Folding for `{start_of_x}`/`{end_of_x}` blocks
92
- - Parser warnings displayed on their source line for malformed directives, invalid metadata, and malformed chords
93
- - Warns (non-blocking) when a "once per song" directive like `{title:}` or `{key:}` is repeated
110
+ - Inline parser diagnostics for malformed directives, invalid metadata, and malformed chords
111
+ - Non-blocking warnings for repeated single-value metadata and unclosed sections, with an action to insert the missing closing directive
94
112
  - Suggests canonical spellings for valid legacy abbreviations such as `Asus` to `Asus4`, `AM7` to `Amaj7`, and `D+` to `Daug`, with an individual replacement action
95
113
  - Exposes `getChordNotationSuggestions()` and `normalizeChordNotationText(content)` for hosts that want to preview or apply grouped normalization
114
+ - Built-in search and replace, also available programmatically through `openSearch()`
96
115
  - No fixed keyboard shortcut requirement: chords and snippets suggest themselves as you type,
97
- and `insertChord()`/`openCompletionList()` work from a button/tap - useful since `Ctrl+Space`
98
- and its usual alternates are unreliable across OS/keyboard layouts
116
+ and `insertChord()`/`openCompletionList()` can be called from a button or touch control
117
+
118
+ ### Localization
119
+
120
+ Provide `searchLabels` and `lintLabels` callbacks when creating the editor to translate the
121
+ search panel and lint messages. Call `refreshLint()` after changing the active language so
122
+ existing diagnostics are regenerated with the new labels. The exported `SearchLabels` and
123
+ `LintLabels` types describe the supported strings.
99
124
 
100
125
  ### Snippets
101
126
 
package/dist/index.cjs CHANGED
@@ -112,6 +112,35 @@ function chordCompletionSource(context) {
112
112
 
113
113
  // src/autocomplete/snippets.ts
114
114
  var import_autocomplete = require("@codemirror/autocomplete");
115
+ function sectionShortcut(startDirective, endDirective, label, detail) {
116
+ return {
117
+ label,
118
+ type: "directive",
119
+ detail,
120
+ apply: (view, completion, from, to) => {
121
+ const line = view.state.doc.lineAt(from);
122
+ let closingAt = view.state.doc.length;
123
+ for (let lineNumber = line.number + 1; lineNumber <= view.state.doc.lines; lineNumber++) {
124
+ const nextLine = view.state.doc.line(lineNumber);
125
+ if (!nextLine.text.trim() || /^\s*\{\s*[A-Za-z_][\w]*\b/.test(nextLine.text)) {
126
+ closingAt = nextLine.from;
127
+ break;
128
+ }
129
+ }
130
+ const opening = `{${startDirective}}`;
131
+ const previousCharacter = closingAt > 0 ? view.state.doc.sliceString(closingAt - 1, closingAt) : "";
132
+ const closing = `${previousCharacter && previousCharacter !== "\n" ? "\n" : ""}{${endDirective}}
133
+ `;
134
+ view.dispatch({
135
+ changes: [
136
+ { from, to, insert: opening },
137
+ { from: closingAt, insert: closing }
138
+ ],
139
+ selection: { anchor: from + opening.length }
140
+ });
141
+ }
142
+ };
143
+ }
115
144
  var CHORDPRO_SNIPPETS = [
116
145
  (0, import_autocomplete.snippetCompletion)("{album: ${value}}", { label: "album", type: "directive" }),
117
146
  (0, import_autocomplete.snippetCompletion)("{arranger: ${value}}", { label: "arranger", type: "directive" }),
@@ -138,25 +167,25 @@ var CHORDPRO_SNIPPETS = [
138
167
  label: "chorus",
139
168
  type: "directive"
140
169
  }),
141
- (0, import_autocomplete.snippetCompletion)("{start_of_chorus}", { label: "soc", type: "directive", detail: "start_of_chorus" }),
170
+ sectionShortcut("start_of_chorus", "end_of_chorus", "soc", "start_of_chorus"),
142
171
  (0, import_autocomplete.snippetCompletion)("{end_of_chorus}", { label: "eoc", type: "directive", detail: "end_of_chorus" }),
143
172
  (0, import_autocomplete.snippetCompletion)("{start_of_verse: ${Verse} ${1}}\n${lyrics}\n{end_of_verse}", {
144
173
  label: "verse",
145
174
  type: "directive"
146
175
  }),
147
- (0, import_autocomplete.snippetCompletion)("{start_of_verse}", { label: "sov", type: "directive", detail: "start_of_verse" }),
176
+ sectionShortcut("start_of_verse", "end_of_verse", "sov", "start_of_verse"),
148
177
  (0, import_autocomplete.snippetCompletion)("{end_of_verse}", { label: "eov", type: "directive", detail: "end_of_verse" }),
149
178
  (0, import_autocomplete.snippetCompletion)("{start_of_bridge: ${Bridge}}\n${lyrics}\n{end_of_bridge}", {
150
179
  label: "bridge",
151
180
  type: "directive"
152
181
  }),
153
- (0, import_autocomplete.snippetCompletion)("{start_of_bridge}", { label: "sob", type: "directive", detail: "start_of_bridge" }),
182
+ sectionShortcut("start_of_bridge", "end_of_bridge", "sob", "start_of_bridge"),
154
183
  (0, import_autocomplete.snippetCompletion)("{end_of_bridge}", { label: "eob", type: "directive", detail: "end_of_bridge" }),
155
184
  (0, import_autocomplete.snippetCompletion)(
156
185
  "{start_of_tab}\ne|-${1}--------------------------------|\nB|----------------------------------|\nG|----------------------------------|\nD|----------------------------------|\nA|----------------------------------|\nE|----------------------------------|\n{end_of_tab}",
157
186
  { label: "tab", type: "directive" }
158
187
  ),
159
- (0, import_autocomplete.snippetCompletion)("{start_of_tab}", { label: "sot", type: "directive", detail: "start_of_tab" }),
188
+ sectionShortcut("start_of_tab", "end_of_tab", "sot", "start_of_tab"),
160
189
  (0, import_autocomplete.snippetCompletion)("{end_of_tab}", { label: "eot", type: "directive", detail: "end_of_tab" }),
161
190
  (0, import_autocomplete.snippetCompletion)("{define: ${Am} base-fret ${1} frets ${0 0 0 0 0 0} fingers ${0 0 0 0 0 0}}", {
162
191
  label: "define",
@@ -524,6 +553,14 @@ function normalizeChordNotationText(content) {
524
553
  }
525
554
 
526
555
  // src/linting.ts
556
+ var defaultLintLabels = {
557
+ duplicateDirective: (directive, firstLine) => `"${directive}" was already defined on line ${firstLine}; this value replaces it.`,
558
+ parserWarning: (warning) => warning.message,
559
+ sectionMessage: (endDirective) => `This section must be closed with {${endDirective}}.`,
560
+ sectionAction: (endDirective) => `Insert {${endDirective}}`,
561
+ chordNotationMessage: (replacement, reason) => `Use "${replacement}". ${reason}`,
562
+ chordNotationAction: (replacement) => `Replace with ${replacement}`
563
+ };
527
564
  var SINGULAR_DIRECTIVES = {
528
565
  title: "title",
529
566
  t: "title",
@@ -550,161 +587,184 @@ var SECTION_STARTS = {
550
587
  sot: "end_of_tab"
551
588
  };
552
589
  var SECTION_ENDS = /* @__PURE__ */ new Set(["end_of_chorus", "eoc", "end_of_verse", "eov", "end_of_bridge", "eob", "end_of_tab", "eot"]);
553
- var duplicateDirectiveLinter = (0, import_lint2.linter)((view) => {
554
- const diagnostics = [];
555
- const firstSeenAtLine = /* @__PURE__ */ new Map();
556
- for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
557
- const line = view.state.doc.line(lineNumber);
558
- const match = line.text.match(DIRECTIVE_LINE);
559
- if (!match) continue;
560
- const canonical = SINGULAR_DIRECTIVES[match[1].toLowerCase()];
561
- if (!canonical) continue;
562
- const firstLine = firstSeenAtLine.get(canonical);
563
- if (firstLine === void 0) {
564
- firstSeenAtLine.set(canonical, lineNumber);
590
+ function hasExplicitSectionEndAhead(view, lineNumber, endDirective) {
591
+ for (let nextLineNumber = lineNumber + 1; nextLineNumber <= view.state.doc.lines; nextLineNumber++) {
592
+ const nextLine = view.state.doc.line(nextLineNumber);
593
+ if (!nextLine.text.trim()) {
565
594
  continue;
566
595
  }
567
- diagnostics.push({
568
- from: line.from,
569
- to: line.from + match[0].length,
570
- severity: "warning",
571
- message: `"${canonical}" ya se defini\xF3 en la l\xEDnea ${firstLine}; este valor la reemplaza.`
572
- });
573
- }
574
- return diagnostics;
575
- });
576
- var parserWarningLinter = (0, import_lint2.linter)((view) => {
577
- const parser = new import_parser.ChordProParser();
578
- parser.parse(view.state.doc.toString());
579
- return parser.warnings.flatMap((warning) => {
580
- if (warning.code === "empty_sheet") {
581
- return [];
596
+ const directive = nextLine.text.match(DIRECTIVE_LINE)?.[1].toLowerCase();
597
+ if (!directive) {
598
+ continue;
582
599
  }
583
- if (warning.lineNumber < 1 || warning.lineNumber > view.state.doc.lines) {
584
- return [];
600
+ return directive === endDirective || endDirective === "end_of_chorus" && directive === "eoc" || endDirective === "end_of_verse" && directive === "eov" || endDirective === "end_of_bridge" && directive === "eob" || endDirective === "end_of_tab" && directive === "eot";
601
+ }
602
+ return false;
603
+ }
604
+ function createLintExtensions(getLabels = () => defaultLintLabels) {
605
+ const duplicateDirectiveLinter = (0, import_lint2.linter)((view) => {
606
+ const diagnostics = [];
607
+ const firstSeenAtLine = /* @__PURE__ */ new Map();
608
+ const labels = getLabels();
609
+ for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
610
+ const line = view.state.doc.line(lineNumber);
611
+ const match = line.text.match(DIRECTIVE_LINE);
612
+ if (!match) continue;
613
+ const canonical = SINGULAR_DIRECTIVES[match[1].toLowerCase()];
614
+ if (!canonical) continue;
615
+ const firstLine = firstSeenAtLine.get(canonical);
616
+ if (firstLine === void 0) {
617
+ firstSeenAtLine.set(canonical, lineNumber);
618
+ continue;
619
+ }
620
+ diagnostics.push({
621
+ from: line.from,
622
+ to: line.from + match[0].length,
623
+ severity: "warning",
624
+ message: labels.duplicateDirective(canonical, firstLine)
625
+ });
585
626
  }
586
- const line = view.state.doc.line(warning.lineNumber);
587
- return [{
588
- from: line.from,
589
- to: line.to,
590
- severity: "warning",
591
- message: warning.message
592
- }];
627
+ return diagnostics;
593
628
  });
594
- }, { delay: 0 });
595
- var unclosedSectionLinter = (0, import_lint2.linter)((view) => {
596
- const diagnostics = [];
597
- let openSection = null;
598
- let sectionHasContent = false;
599
- for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
600
- const line = view.state.doc.line(lineNumber);
601
- const match = line.text.match(DIRECTIVE_LINE);
602
- const directive = match?.[1].toLowerCase();
603
- if (directive && SECTION_STARTS[directive]) {
604
- if (openSection) {
605
- openSection.insertionAt = line.from;
606
- openSection.insertionTo = line.from;
607
- diagnostics.push(sectionDiagnostic(openSection));
629
+ const parserWarningLinter = (0, import_lint2.linter)((view) => {
630
+ const parser = new import_parser.ChordProParser();
631
+ parser.parse(view.state.doc.toString());
632
+ const labels = getLabels();
633
+ return parser.warnings.flatMap((warning) => {
634
+ if (warning.code === "empty_sheet") {
635
+ return [];
608
636
  }
609
- openSection = {
610
- endDirective: SECTION_STARTS[directive],
611
- lineFrom: line.from,
612
- lineTo: line.to,
613
- insertionAt: line.from,
614
- insertionTo: line.from
615
- };
616
- sectionHasContent = false;
617
- continue;
618
- }
619
- if (directive && SECTION_ENDS.has(directive)) {
620
- openSection = null;
621
- sectionHasContent = false;
622
- continue;
623
- }
624
- if (openSection && directive) {
625
- openSection.insertionAt = line.from;
626
- openSection.insertionTo = line.from;
627
- diagnostics.push(sectionDiagnostic(openSection));
628
- openSection = null;
629
- sectionHasContent = false;
630
- continue;
631
- }
632
- if (openSection && !line.text.trim()) {
633
- const nextDirective = nextNonBlankDirective(view, lineNumber);
634
- if (sectionHasContent) {
637
+ if (warning.lineNumber < 1 || warning.lineNumber > view.state.doc.lines) {
638
+ return [];
639
+ }
640
+ const line = view.state.doc.line(warning.lineNumber);
641
+ return [{
642
+ from: line.from,
643
+ to: line.to,
644
+ severity: "warning",
645
+ message: labels.parserWarning(warning)
646
+ }];
647
+ });
648
+ }, { delay: 0 });
649
+ const unclosedSectionLinter = (0, import_lint2.linter)((view) => {
650
+ const diagnostics = [];
651
+ let openSection = null;
652
+ let sectionHasContent = false;
653
+ for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
654
+ const line = view.state.doc.line(lineNumber);
655
+ const match = line.text.match(DIRECTIVE_LINE);
656
+ const directive = match?.[1].toLowerCase();
657
+ if (directive && SECTION_STARTS[directive]) {
658
+ if (openSection) {
659
+ openSection.insertionAt = line.from;
660
+ openSection.insertionTo = line.from;
661
+ diagnostics.push(sectionDiagnostic(openSection, getLabels()));
662
+ }
663
+ openSection = {
664
+ endDirective: SECTION_STARTS[directive],
665
+ lineFrom: line.from,
666
+ lineTo: line.to,
667
+ insertionAt: line.from,
668
+ insertionTo: line.from
669
+ };
670
+ sectionHasContent = false;
671
+ continue;
672
+ }
673
+ if (directive && SECTION_ENDS.has(directive)) {
674
+ openSection = null;
675
+ sectionHasContent = false;
676
+ continue;
677
+ }
678
+ if (openSection && directive) {
635
679
  openSection.insertionAt = line.from;
636
- openSection.insertionTo = nextDirective ? nextNonBlankDirectiveLine(view, lineNumber) : line.from;
637
- diagnostics.push(sectionDiagnostic(openSection));
680
+ openSection.insertionTo = line.from;
681
+ diagnostics.push(sectionDiagnostic(openSection, getLabels()));
638
682
  openSection = null;
639
683
  sectionHasContent = false;
684
+ continue;
640
685
  }
641
- continue;
642
- }
643
- if (openSection && lineNumber === view.state.doc.lines) {
644
- openSection.insertionAt = view.state.doc.length;
645
- openSection.insertionTo = view.state.doc.length;
646
- }
647
- if (openSection) {
648
- sectionHasContent = true;
649
- }
650
- }
651
- function nextNonBlankDirective(view2, lineNumber) {
652
- const directiveLine = nextNonBlankDirectiveLine(view2, lineNumber);
653
- return directiveLine < view2.state.doc.length ? view2.state.doc.lineAt(directiveLine).text.match(DIRECTIVE_LINE)?.[1].toLowerCase() ?? null : null;
654
- }
655
- function nextNonBlankDirectiveLine(view2, lineNumber) {
656
- for (let nextLineNumber = lineNumber + 1; nextLineNumber <= view2.state.doc.lines; nextLineNumber++) {
657
- const nextLine = view2.state.doc.line(nextLineNumber);
658
- if (!nextLine.text.trim()) {
686
+ if (openSection && !line.text.trim()) {
687
+ if (hasExplicitSectionEndAhead(view, lineNumber, openSection.endDirective)) {
688
+ continue;
689
+ }
690
+ const nextDirective = nextNonBlankDirective(view, lineNumber);
691
+ if (sectionHasContent) {
692
+ openSection.insertionAt = line.from;
693
+ openSection.insertionTo = nextDirective ? nextNonBlankDirectiveLine(view, lineNumber) : line.from;
694
+ diagnostics.push(sectionDiagnostic(openSection, getLabels()));
695
+ openSection = null;
696
+ sectionHasContent = false;
697
+ }
659
698
  continue;
660
699
  }
661
- if (nextLine.text.match(DIRECTIVE_LINE)) {
662
- return nextLine.from;
700
+ if (openSection && lineNumber === view.state.doc.lines) {
701
+ openSection.insertionAt = view.state.doc.length;
702
+ openSection.insertionTo = view.state.doc.length;
703
+ }
704
+ if (openSection) {
705
+ sectionHasContent = true;
663
706
  }
664
- return view2.state.doc.length;
665
707
  }
666
- return view2.state.doc.length;
667
- }
668
- if (openSection) {
669
- diagnostics.push(sectionDiagnostic(openSection));
670
- }
671
- return diagnostics;
672
- }, { delay: 0 });
673
- function sectionDiagnostic(section) {
674
- return {
675
- from: section.lineFrom,
676
- to: section.lineTo,
677
- severity: "warning",
678
- message: `Falta cerrar esta secci\xF3n con {${section.endDirective}}.`,
679
- actions: [{
680
- name: `Insertar {${section.endDirective}}`,
681
- apply: (view, from, to) => {
682
- const previousCharacter = section.insertionAt > 0 ? view.state.doc.sliceString(section.insertionAt - 1, section.insertionAt) : "";
683
- const needsLeadingNewline = previousCharacter !== "\n";
684
- const insertion = `${needsLeadingNewline ? "\n" : ""}{${section.endDirective}}${section.insertionTo < view.state.doc.length ? "\n" : ""}`;
685
- view.dispatch({ changes: { from: section.insertionAt, to: section.insertionTo, insert: insertion } });
708
+ function nextNonBlankDirective(view2, lineNumber) {
709
+ const directiveLine = nextNonBlankDirectiveLine(view2, lineNumber);
710
+ return directiveLine < view2.state.doc.length ? view2.state.doc.lineAt(directiveLine).text.match(DIRECTIVE_LINE)?.[1].toLowerCase() ?? null : null;
711
+ }
712
+ function nextNonBlankDirectiveLine(view2, lineNumber) {
713
+ for (let nextLineNumber = lineNumber + 1; nextLineNumber <= view2.state.doc.lines; nextLineNumber++) {
714
+ const nextLine = view2.state.doc.line(nextLineNumber);
715
+ if (!nextLine.text.trim()) {
716
+ continue;
717
+ }
718
+ if (nextLine.text.match(DIRECTIVE_LINE)) {
719
+ return nextLine.from;
720
+ }
721
+ return view2.state.doc.length;
686
722
  }
687
- }]
688
- };
689
- }
690
- var chordNotationLinter = (0, import_lint2.linter)((view) => {
691
- const diagnostics = [];
692
- for (const replacement of findChordNotationReplacements(view.state.doc.toString())) {
693
- diagnostics.push({
694
- from: replacement.from,
695
- to: replacement.to,
696
- severity: "info",
697
- message: `Usa "${replacement.replacement}". ${replacement.reason}`,
723
+ return view2.state.doc.length;
724
+ }
725
+ if (openSection) {
726
+ diagnostics.push(sectionDiagnostic(openSection, getLabels()));
727
+ }
728
+ return diagnostics;
729
+ }, { delay: 0 });
730
+ function sectionDiagnostic(section, labels) {
731
+ return {
732
+ from: section.lineFrom,
733
+ to: section.lineTo,
734
+ severity: "warning",
735
+ message: labels.sectionMessage(section.endDirective),
698
736
  actions: [{
699
- name: `Reemplazar por ${replacement.replacement}`,
700
- apply: (targetView, actionFrom, actionTo) => {
701
- targetView.dispatch({ changes: { from: actionFrom, to: actionTo, insert: `[${replacement.replacement}]` } });
737
+ name: labels.sectionAction(section.endDirective),
738
+ apply: (view, from, to) => {
739
+ const previousCharacter = section.insertionAt > 0 ? view.state.doc.sliceString(section.insertionAt - 1, section.insertionAt) : "";
740
+ const needsLeadingNewline = previousCharacter !== "\n";
741
+ const insertion = `${needsLeadingNewline ? "\n" : ""}{${section.endDirective}}${section.insertionTo < view.state.doc.length ? "\n" : ""}`;
742
+ view.dispatch({ changes: { from: section.insertionAt, to: section.insertionTo, insert: insertion } });
702
743
  }
703
744
  }]
704
- });
745
+ };
705
746
  }
706
- return diagnostics;
707
- });
747
+ const chordNotationLinter = (0, import_lint2.linter)((view) => {
748
+ const diagnostics = [];
749
+ const labels = getLabels();
750
+ for (const replacement of findChordNotationReplacements(view.state.doc.toString())) {
751
+ diagnostics.push({
752
+ from: replacement.from,
753
+ to: replacement.to,
754
+ severity: "info",
755
+ message: labels.chordNotationMessage(replacement.replacement, replacement.reason),
756
+ actions: [{
757
+ name: labels.chordNotationAction(replacement.replacement),
758
+ apply: (targetView, actionFrom, actionTo) => {
759
+ targetView.dispatch({ changes: { from: actionFrom, to: actionTo, insert: `[${replacement.replacement}]` } });
760
+ }
761
+ }]
762
+ });
763
+ }
764
+ return diagnostics;
765
+ });
766
+ return [duplicateDirectiveLinter, parserWarningLinter, unclosedSectionLinter, chordNotationLinter];
767
+ }
708
768
 
709
769
  // src/themes/base.ts
710
770
  var import_view2 = require("@codemirror/view");
@@ -1303,16 +1363,14 @@ function createChordProEditor(options) {
1303
1363
  (update.view.hasFocus ? options.onFocus : options.onBlur)?.();
1304
1364
  }
1305
1365
  });
1366
+ const lintExtensions = createLintExtensions(options.lintLabels ?? (() => defaultLintLabels));
1306
1367
  const state = import_state2.EditorState.create({
1307
1368
  doc: options.doc ?? "",
1308
1369
  extensions: [
1309
1370
  basicSetup(),
1310
1371
  chordPro(),
1311
1372
  chordProFolding,
1312
- duplicateDirectiveLinter,
1313
- parserWarningLinter,
1314
- unclosedSectionLinter,
1315
- chordNotationLinter,
1373
+ ...lintExtensions,
1316
1374
  chordProAutocomplete(),
1317
1375
  themeCompartment.of(themeExtension(options.theme ?? "light")),
1318
1376
  (0, import_search3.search)({ top: true, createPanel: (view2) => createSearchPanel(view2, options.searchLabels?.()) }),
@@ -1353,6 +1411,7 @@ function createChordProEditor(options) {
1353
1411
  }
1354
1412
  return normalization.suggestions;
1355
1413
  },
1414
+ refreshLint: () => view.dispatch({}),
1356
1415
  focus: () => view.focus(),
1357
1416
  destroy: () => view.destroy()
1358
1417
  };