Skip to content

Commit

Permalink
Add more formatting tools
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Nov 7, 2023
1 parent c6135a9 commit 5ced129
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 22 deletions.
7 changes: 6 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,10 @@
"example": "1"
}
}
}
},
"bold": "Bold",
"italic": "Italic",
"strikethrough": "Strikethrough",
"code": "Code",
"link": "Link"
}
97 changes: 76 additions & 21 deletions app/lib/pages/notes/card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class _NoteCardState extends State<NoteCard> {

bool _loading = false;

final _formattingScrollController = ScrollController();

@override
void initState() {
super.initState();
Expand All @@ -73,6 +75,15 @@ class _NoteCardState extends State<NoteCard> {
});
}

@override
void dispose() {
_nameController.dispose();
_descriptionController.dispose();
_nameFocus.dispose();
_formattingScrollController.dispose();
super.dispose();
}

@override
void didUpdateWidget(covariant NoteCard oldWidget) {
super.didUpdateWidget(oldWidget);
Expand All @@ -96,15 +107,18 @@ class _NoteCardState extends State<NoteCard> {
var description = _descriptionController.text;
final selection = _descriptionController.selection;
if (!selection.isValid) return;
final start = selection.baseOffset;
final lineStart = description.lastIndexOf("\n", start - 1);
final start = max(1, selection.start);
final end = max(1, selection.end);
final lineStart = description.lastIndexOf("\n", start - 1) + 1;
description = switch (position) {
PastePositing.line => description.substring(0, lineStart + 1) +
PastePositing.line => description.substring(0, lineStart) +
text +
description.substring(lineStart + 1),
description.substring(lineStart),
PastePositing.selection => description.substring(0, start) +
text +
description.substring(selection.extentOffset),
description.substring(start, end) +
text +
description.substring(end),
};
_descriptionController.text = description;
_descriptionController.selection = TextSelection.collapsed(
Expand Down Expand Up @@ -332,22 +346,63 @@ class _NoteCardState extends State<NoteCard> {
if (widget.primary)
SizedBox(
height: 50,
child: ListView(scrollDirection: Axis.horizontal, children: [
...[
PhosphorIconsLight.textHOne,
PhosphorIconsLight.textHTwo,
PhosphorIconsLight.textHThree,
PhosphorIconsLight.textHFour,
PhosphorIconsLight.textHFive,
PhosphorIconsLight.textHSix
].mapIndexed((index, element) => IconButton(
icon: PhosphorIcon(element),
onPressed: () => _addDescription(
PastePositing.line,
"${"#" * (index + 1)} ",
),
))
]),
child: Scrollbar(
controller: _formattingScrollController,
child: ListView(
controller: _formattingScrollController,
scrollDirection: Axis.horizontal,
children: [
...[
PhosphorIconsLight.textHOne,
PhosphorIconsLight.textHTwo,
PhosphorIconsLight.textHThree,
PhosphorIconsLight.textHFour,
PhosphorIconsLight.textHFive,
PhosphorIconsLight.textHSix
].mapIndexed((index, element) => IconButton(
icon: PhosphorIcon(element),
onPressed: () => _addDescription(
PastePositing.line,
"${"#" * (index + 1)} ",
),
)),
const SizedBox(width: 8),
...[
(
'**',
PhosphorIconsLight.textB,
AppLocalizations.of(context).bold
),
(
'*',
PhosphorIconsLight.textItalic,
AppLocalizations.of(context).italic
),
(
'~~',
PhosphorIconsLight.textStrikethrough,
AppLocalizations.of(context).strikethrough
),
(
'`',
PhosphorIconsLight.code,
AppLocalizations.of(context).code
),
(
'[',
PhosphorIconsLight.link,
AppLocalizations.of(context).link
),
].map((e) => IconButton(
icon: PhosphorIcon(e.$2),
tooltip: e.$3,
onPressed: () => _addDescription(
PastePositing.selection,
e.$1,
),
)),
]),
),
),
MarkdownField(
decoration: InputDecoration(
Expand Down

0 comments on commit 5ced129

Please sign in to comment.