feat: add keyboard shortcuts for notes, the note list and the app
This commit is contained in:
parent
ed2de5e67f
commit
722390ecec
9 changed files with 532 additions and 60 deletions
|
|
@ -110,7 +110,7 @@ class MarkdownController extends TextEditingController {
|
|||
_updateMatches();
|
||||
}
|
||||
|
||||
final Map<String, TextStyle> theme;
|
||||
Map<String, TextStyle> theme;
|
||||
|
||||
List<String> _terms = const [];
|
||||
List<TextRange> _matches = const [];
|
||||
|
|
@ -375,3 +375,40 @@ TextEditingValue indentLines(TextEditingValue value, {bool outdent = false}) {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Toggles emphasis [marker] (`*` or `**`) around the selection, leaving the
|
||||
/// selection on the same text. With nothing selected, inserts an empty pair.
|
||||
TextEditingValue toggleEmphasis(TextEditingValue value, String marker) {
|
||||
final sel = value.selection;
|
||||
if (!sel.isValid) return value;
|
||||
final text = value.text;
|
||||
final s = sel.start;
|
||||
final e = sel.end;
|
||||
final char = marker[0];
|
||||
|
||||
var before = 0;
|
||||
while (before < s && text[s - before - 1] == char) {
|
||||
before++;
|
||||
}
|
||||
var after = 0;
|
||||
while (e + after < text.length && text[e + after] == char) {
|
||||
after++;
|
||||
}
|
||||
// A run of 3 is bold plus italic, so either marker can be removed from it.
|
||||
final run = before < after ? before : after;
|
||||
final present = marker.length == 2 ? run >= 2 : run == 1 || run == 3;
|
||||
|
||||
final len = marker.length;
|
||||
if (present) {
|
||||
return TextEditingValue(
|
||||
text: text.replaceRange(e, e + len, '').replaceRange(s - len, s, ''),
|
||||
selection: TextSelection(
|
||||
baseOffset: sel.baseOffset - len, extentOffset: sel.extentOffset - len),
|
||||
);
|
||||
}
|
||||
return TextEditingValue(
|
||||
text: text.replaceRange(s, e, '$marker${text.substring(s, e)}$marker'),
|
||||
selection: TextSelection(
|
||||
baseOffset: sel.baseOffset + len, extentOffset: sel.extentOffset + len),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue