Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/ui/screens/canvas_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class CanvasScreen extends StatelessWidget {
context.read<CanvasCubit>().toggleDrawingMode();
}

void _handleAddText(BuildContext context) {
context.read<CanvasCubit>().addText('New Text');
}

@override
Widget build(BuildContext context) {
return KeyboardShortcuts(
Expand All @@ -94,6 +98,7 @@ class CanvasScreen extends StatelessWidget {
onNew: () => _handleNew(context),
onClear: () => _handleClear(context),
onToggleDrawing: () => _handleToggleDrawing(context),
onAddText: () => _handleAddText(context),
child: Scaffold(
backgroundColor: ColorConstants.uiWhite,
appBar: AppBar(
Expand Down Expand Up @@ -418,7 +423,8 @@ class CanvasScreen extends StatelessWidget {
child: const Icon(Icons.text_fields,
color: ColorConstants.dialogButtonBlue),
),
title: const Text('Add Text'),
title: const Text(
kIsWeb ? 'Add Text (Ctrl+T)' : 'Add Text'),
subtitle:
const Text('Add and format text on canvas'),
onTap: () {
Expand Down Expand Up @@ -548,12 +554,15 @@ class CanvasScreen extends StatelessWidget {
}
}

// Helper method to get appropriate image provider for web and mobile
ImageProvider _getImageProvider(String imagePath) {
if (kIsWeb && imagePath.startsWith('data:')) {
// On web, if it's a data URL, decode it and use MemoryImage
final String base64String = imagePath.split(',')[1];
final Uint8List bytes = base64Decode(base64String);
return MemoryImage(bytes);
} else {
// On mobile or if it's a file path, use FileImage
return FileImage(File(imagePath));
}
}
Expand All @@ -570,6 +579,7 @@ class CanvasScreen extends StatelessWidget {
children: [
_shortcutItem('Ctrl + S', 'Save page'),
_shortcutItem('Ctrl + N', 'New page'),
_shortcutItem('Ctrl + T', 'Add text'),
_shortcutItem('Ctrl + Z', 'Undo'),
_shortcutItem('Ctrl + Shift + Z', 'Redo'),
_shortcutItem('Ctrl + Y', 'Redo (alternative)'),
Expand Down Expand Up @@ -690,4 +700,4 @@ class _DraggableTextBoxState extends State<_DraggableTextBox> {
),
);
}
}
}
10 changes: 10 additions & 0 deletions lib/utils/web_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class KeyboardShortcuts extends StatelessWidget {
final VoidCallback? onNew;
final VoidCallback? onClear;
final VoidCallback? onToggleDrawing;
final VoidCallback? onAddText;

const KeyboardShortcuts({
super.key,
Expand All @@ -34,6 +35,7 @@ class KeyboardShortcuts extends StatelessWidget {
this.onNew,
this.onClear,
this.onToggleDrawing,
this.onAddText,
});

@override
Expand Down Expand Up @@ -98,6 +100,14 @@ class KeyboardShortcuts extends StatelessWidget {
const SingleActivator(LogicalKeyboardKey.keyD, meta: true): () {
onToggleDrawing?.call();
},

// Add Text: Ctrl/Cmd + T
const SingleActivator(LogicalKeyboardKey.keyT, control: true): () {
onAddText?.call();
},
const SingleActivator(LogicalKeyboardKey.keyT, meta: true): () {
onAddText?.call();
},
},
child: Focus(
autofocus: true,
Expand Down
Loading