diff --git a/lib/data/prefs.dart b/lib/data/prefs.dart index badab6d765..769bb27b5a 100644 --- a/lib/data/prefs.dart +++ b/lib/data/prefs.dart @@ -105,6 +105,7 @@ abstract class Prefs { static late final PlainPref autoClearWhiteboardOnExit; static late final PlainPref disableEraserAfterUse; + static late final PlainPref eraserOnStylusButtonPressAndRelease; static late final PlainPref hideFingerDrawingToggle; static late final PlainPref> recentColorsChronological; @@ -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', []); diff --git a/lib/i18n/strings_en.g.dart b/lib/i18n/strings_en.g.dart index 61659f1e01..b8a867f8ec 100644 --- a/lib/i18n/strings_en.g.dart +++ b/lib/i18n/strings_en.g.dart @@ -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'; @@ -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'; diff --git a/lib/pages/editor/editor.dart b/lib/pages/editor/editor.dart index 000ad6ed07..d68d46a312 100644 --- a/lib/pages/editor/editor.dart +++ b/lib/pages/editor/editor.dart @@ -731,20 +731,49 @@ class EditorState extends State { // 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) { diff --git a/lib/pages/home/settings.dart b/lib/pages/home/settings.dart index a934940c3c..c2e11d574b 100644 --- a/lib/pages/home/settings.dart +++ b/lib/pages/home/settings.dart @@ -352,6 +352,12 @@ class _SettingsPageState extends State { 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: () { @@ -588,3 +594,4 @@ class _SettingsPageState extends State { super.dispose(); } } +