Skip to content

fix. Stylus button press changes tool to Eraser but do not erase. #1428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions lib/data/prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ abstract class Prefs {
static late final PlainPref<bool> autoClearWhiteboardOnExit;

static late final PlainPref<bool> disableEraserAfterUse;
static late final PlainPref<bool> eraserOnStylusButtonPressAndRelease;
static late final PlainPref<bool> hideFingerDrawingToggle;

static late final PlainPref<List<String>> recentColorsChronological;
Expand Down Expand Up @@ -217,6 +218,7 @@ abstract class Prefs {
autoClearWhiteboardOnExit = PlainPref('autoClearWhiteboardOnExit', false);

disableEraserAfterUse = PlainPref('disableEraserAfterUse', false);
eraserOnStylusButtonPressAndRelease = PlainPref('eraserOnStylusButtonPressAndRelease', false);
hideFingerDrawingToggle = PlainPref('hideFingerDrawingToggle', false);

recentColorsChronological = PlainPref('recentColorsChronological', []);
Expand Down
2 changes: 2 additions & 0 deletions lib/i18n/strings_en.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ class TranslationsSettingsPrefLabelsEn {
String get maxImageSize => 'Maximum image size';
String get autoClearWhiteboardOnExit => 'Auto-clear the whiteboard';
String get disableEraserAfterUse => 'Auto-disable the eraser';
String get eraserOnStylusButtonPressAndRelease => 'Eraser on stylus button press and release';
String get hideFingerDrawingToggle => 'Hide the finger drawing toggle';
String get editorPromptRename => 'Prompt you to rename new notes';
String get hideHomeBackgrounds => 'Hide backgrounds on the home screen';
Expand All @@ -400,6 +401,7 @@ class TranslationsSettingsPrefDescriptionsEn {
String get preferGreyscale => 'For e-ink displays';
String get autoClearWhiteboardOnExit => 'Clears the whiteboard after you exit the app';
String get disableEraserAfterUse => 'Automatically switches back to the pen after using the eraser';
String get eraserOnStylusButtonPressAndRelease => 'Switch to eraser pressing stylus button and releasing it';
String get maxImageSize => 'Larger images will be compressed';
late final TranslationsSettingsPrefDescriptionsHideFingerDrawingEn hideFingerDrawing = TranslationsSettingsPrefDescriptionsHideFingerDrawingEn.internal(_root);
String get editorPromptRename => 'You can always rename notes later';
Expand Down
49 changes: 39 additions & 10 deletions lib/pages/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -731,20 +731,49 @@ class EditorState extends State<Editor> {
// whether the stylus button is or was pressed
stylusButtonPressed = stylusButtonPressed || buttonPressed;

if (isHovering) {
if (buttonPressed) {
if (currentTool is Eraser) return;
tmpTool = currentTool;
currentTool = Eraser();
setState(() {});
} else {
if (tmpTool != null) {
currentTool = tmpTool!;
tmpTool = null;
if (!Prefs.eraserOnStylusButtonPressAndRelease.value) {
// standard behavior of stylus button, while holding is erasing
if (isHovering) {
if (buttonPressed) {
if (currentTool is Eraser) return;
tmpTool = currentTool;
currentTool = Eraser();
setState(() {});
} else {
if (tmpTool != null) {
currentTool = tmpTool!;
tmpTool = null;
setState(() {});
}
}
}
}
else {
// some pens do not send moving events when stylus button is pressed
// so switch to eraser when button is pressed and back on next press
if (isHovering) {
if (buttonPressed) {
// switch to Eraser
if (currentTool is Eraser) {
if (tmpTool != null) {
// change back original tool
currentTool = tmpTool!;
tmpTool = null;
setState(() {});
}
else {
return; // when I am on eraser and previous tool is not set, it means that Eraser is main tool
}
}
else {
tmpTool = currentTool;
currentTool = Eraser();
setState(() {});
}
}
}
}

}

void onMoveImage(EditorImage image, Rect offset) {
Expand Down
7 changes: 7 additions & 0 deletions lib/pages/home/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@
icon: FontAwesomeIcons.eraser,
pref: Prefs.disableEraserAfterUse,
),
SettingsSwitch(
title: t.settings.prefLabels.eraserOnStylusButtonPressAndRelease,
subtitle: t.settings.prefDescriptions.eraserOnStylusButtonPressAndRelease,
icon: FontAwesomeIcons.eraser,
pref: Prefs.eraserOnStylusButtonPressAndRelease,
),
SettingsSwitch(
title: t.settings.prefLabels.hideFingerDrawingToggle,
subtitle: () {
Expand Down Expand Up @@ -587,4 +593,5 @@
UpdateManager.status.removeListener(onChanged);
super.dispose();
}
}

Check notice on line 597 in lib/pages/home/settings.dart

View workflow job for this annotation

GitHub Actions / Run Flutter tests

Missing a newline at the end of the file.

Try adding a newline at the end of the file. See https://dart.dev/lints/eol_at_end_of_file to learn more about this problem.