-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add (alt-)k/K keyboard commands to add/remove next/previous system br…
…eak.
- Loading branch information
Showing
4 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
_includes/vhv-scripts/editor/addSystemBreakToNextBarline.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{% comment %} | ||
// | ||
// Programmer: Craig Stuart Sapp <[email protected]> | ||
// Creation Date: Wed Jun 5 02:08:33 PDT 2024 | ||
// Last Modified: Wed Jun 5 02:08:40 PDT 2024 | ||
// Filename: addSystemBreakToNextBarline.js | ||
// Web Address: https://verovio.humdrum.org/scripts/addSystemBreakToNextBarline.js | ||
// Syntax: JavaScript 1.8/ECMAScript 5 | ||
// vim: ts=3: ft=javascript | ||
// | ||
// Description: Add a system break to the next barline (or remove break if | ||
// there is already one). | ||
// | ||
{% endcomment %} | ||
|
||
|
||
function addSystemBreakToNextBarline() { | ||
let location = EDITOR.getCursorPosition(); | ||
let index = location.row; | ||
|
||
var contents = getTextFromEditor().split(/\r?\n/); | ||
|
||
let barIndex = -1; | ||
for (let i=index; i<contents.length; i++) { | ||
if (contents[i].match(/^=/)) { | ||
barIndex = i; | ||
break; | ||
} | ||
} | ||
if (barIndex < 1) { | ||
return; | ||
} | ||
|
||
console.warn("LO", contents[barIndex - 1]); | ||
|
||
if (contents[barIndex-1].match(/^!!LO:[LP]B:/)) { | ||
// Remove system break line | ||
var Range = ace.require("ace/range").Range; | ||
var range = new Range(barIndex-1, 0, barIndex, 0); | ||
EDITOR.session.remove(range); | ||
return; | ||
} | ||
|
||
let text = "!!LO:LB:g=original"; | ||
let textIndex = barIndex - 1; | ||
EDITOR.session.insert({ row: textIndex + 1, column: 0 }, text + '\n'); | ||
|
||
// Adjust the cursor position if it is below the inserted line | ||
// if (cursorPosition.row >= lineNumber) { | ||
// cursorPosition.row += 1; | ||
// } | ||
|
||
EDITOR.moveCursorToPosition(location); | ||
} | ||
|
||
|
||
|
56 changes: 56 additions & 0 deletions
56
_includes/vhv-scripts/editor/addSystemBreakToPreviousBarline.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{% comment %} | ||
// | ||
// Programmer: Craig Stuart Sapp <[email protected]> | ||
// Creation Date: Wed Jun 5 02:08:33 PDT 2024 | ||
// Last Modified: Wed Jun 5 02:08:40 PDT 2024 | ||
// Filename: addSystemBreakToPreviousBarline.js | ||
// Web Address: https://verovio.humdrum.org/scripts/addSystemBreakToPreviousBarline.js | ||
// Syntax: JavaScript 1.8/ECMAScript 5 | ||
// vim: ts=3: ft=javascript | ||
// | ||
// Description: Add a system break to the next barline (or remove break if | ||
// there is already one). | ||
// | ||
{% endcomment %} | ||
|
||
|
||
function addSystemBreakToPreviousBarline() { | ||
let location = EDITOR.getCursorPosition(); | ||
let index = location.row; | ||
|
||
var contents = getTextFromEditor().split(/\r?\n/); | ||
|
||
let barIndex = -1; | ||
for (let i=index; i>=1; i--) { | ||
if (contents[i].match(/^=/)) { | ||
barIndex = i; | ||
break; | ||
} | ||
} | ||
if (barIndex < 1) { | ||
return; | ||
} | ||
|
||
console.warn("LO", contents[barIndex - 1]); | ||
|
||
if (contents[barIndex-1].match(/^!!LO:[LP]B:/)) { | ||
// Remove system break line | ||
var Range = ace.require("ace/range").Range; | ||
var range = new Range(barIndex-1, 0, barIndex, 0); | ||
EDITOR.session.remove(range); | ||
location.row--; | ||
EDITOR.moveCursorToPosition(location); | ||
return; | ||
} | ||
|
||
let text = "!!LO:LB:g=original"; | ||
let textIndex = barIndex - 1; | ||
EDITOR.session.insert({ row: textIndex + 1, column: 0 }, text + '\n'); | ||
location.row++; | ||
EDITOR.moveCursorToPosition(location); | ||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters