From b9f8d58ec2b6ba4d74879d6df96ff28ee2a48fbb Mon Sep 17 00:00:00 2001 From: Felipe Teixeira Date: Wed, 11 Dec 2024 21:02:15 -0300 Subject: [PATCH] feat: add preference to disable editor cursor animation --- .../itsaky/androidide/preferences/editorPrefExts.kt | 12 ++++++++++++ .../java/com/itsaky/androidide/ui/CodeEditorView.kt | 6 ++++++ core/resources/src/main/res/values/strings.xml | 2 ++ .../preferences/internal/EditorPreferences.kt | 7 +++++++ 4 files changed, 27 insertions(+) diff --git a/core/app/src/main/java/com/itsaky/androidide/preferences/editorPrefExts.kt b/core/app/src/main/java/com/itsaky/androidide/preferences/editorPrefExts.kt index 537e0ff48e..2d19724d04 100644 --- a/core/app/src/main/java/com/itsaky/androidide/preferences/editorPrefExts.kt +++ b/core/app/src/main/java/com/itsaky/androidide/preferences/editorPrefExts.kt @@ -42,6 +42,7 @@ import com.itsaky.androidide.preferences.internal.EditorPreferences.USE_CUSTOM_F import com.itsaky.androidide.preferences.internal.EditorPreferences.USE_ICU import com.itsaky.androidide.preferences.internal.EditorPreferences.USE_MAGNIFER import com.itsaky.androidide.preferences.internal.EditorPreferences.USE_SOFT_TAB +import com.itsaky.androidide.preferences.internal.EditorPreferences.CURSOR_ANIMATION_ENABLED import com.itsaky.androidide.preferences.internal.EditorPreferences.WORD_WRAP import com.itsaky.androidide.resources.R.drawable import com.itsaky.androidide.resources.R.string @@ -86,6 +87,7 @@ private class CommonConfigurations( addPreference(VisibiblePasswordFlag()) addPreference(DeleteEmptyLines()) addPreference(DeleteTabs()) + addPreference(CursorAnimationEnabled()) addPreference(StickyScrollEnabled()) addPreference(PinLineNumbersEnabled()) addPreference(CompletionsMatchLower()) @@ -147,6 +149,16 @@ private class UseSoftTab( ) : SwitchPreference(setValue = EditorPreferences::useSoftTab::set, getValue = EditorPreferences::useSoftTab::get) +@Parcelize +private class CursorAnimationEnabled( + override val key: String = CURSOR_ANIMATION_ENABLED, + override val title: Int = string.idepref_editor_cursorAnimationEnabled_title, + override val summary: Int? = string.idepref_editor_cursorAnimationEnabled_summary, + override val icon: Int? = drawable.ic_space, // TODO: Add a icon +) : SwitchPreference(setValue = EditorPreferences::cursorAnimationEnabled::set, + getValue = EditorPreferences::cursorAnimationEnabled::get) + + @Parcelize private class TabSize( override val key: String = TAB_SIZE, diff --git a/core/app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt b/core/app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt index 620d9df407..71045c2e99 100644 --- a/core/app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt +++ b/core/app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt @@ -341,6 +341,7 @@ class CodeEditorView( onUseIcuPrefChanged() onDeleteEmptyLinesPrefChanged() onDeleteTabsPrefChanged() + onCursorAnimationPrefChanged() onStickyScrollEnabeldPrefChanged() onPinLineNumbersPrefChanged() } @@ -409,6 +410,10 @@ class CodeEditorView( binding.editor.props.deleteMultiSpaces = if (EditorPreferences.deleteTabsOnBackspace) -1 else 1 } + private fun onCursorAnimationPrefChanged() { + binding.editor.cursorAnimationEnabled = EditorPreferences.cursorAnimationEnabled + } + private fun onStickyScrollEnabeldPrefChanged() { binding.editor.props.stickyScroll = EditorPreferences.stickyScrollEnabled } @@ -460,6 +465,7 @@ class CodeEditorView( EditorPreferences.USE_MAGNIFER -> onMagnifierPrefChanged() EditorPreferences.USE_ICU -> onUseIcuPrefChanged() EditorPreferences.USE_CUSTOM_FONT -> onCustomFontPrefChanged() + EditorPreferences.CURSOR_ANIMATION_ENABLED -> onCursorAnimationPrefChanged() EditorPreferences.DELETE_EMPTY_LINES -> onDeleteEmptyLinesPrefChanged() EditorPreferences.DELETE_TABS_ON_BACKSPACE -> onDeleteTabsPrefChanged() EditorPreferences.STICKY_SCROLL_ENABLED -> onStickyScrollEnabeldPrefChanged() diff --git a/core/resources/src/main/res/values/strings.xml b/core/resources/src/main/res/values/strings.xml index 75493329ca..8eadbe739e 100644 --- a/core/resources/src/main/res/values/strings.xml +++ b/core/resources/src/main/res/values/strings.xml @@ -258,6 +258,8 @@ Swipe up for @@build output@@. Use soft tab Choose whether to use spaces instead of tab character (\\t). + Enable cursor animation + Choose whether to use animation when moving the cursor. Donate Documentation Close diff --git a/utilities/preferences/src/main/java/com/itsaky/androidide/preferences/internal/EditorPreferences.kt b/utilities/preferences/src/main/java/com/itsaky/androidide/preferences/internal/EditorPreferences.kt index fbdfc296f6..e33c746bcd 100644 --- a/utilities/preferences/src/main/java/com/itsaky/androidide/preferences/internal/EditorPreferences.kt +++ b/utilities/preferences/src/main/java/com/itsaky/androidide/preferences/internal/EditorPreferences.kt @@ -43,6 +43,7 @@ object EditorPreferences { const val USE_ICU = "idepref_editor_useIcu" const val USE_SOFT_TAB = "idepref_editor_useSoftTab" const val USE_CUSTOM_FONT = "idepref_editor_useCustomFont" + const val CURSOR_ANIMATION_ENABLED = "idepref_editor_cursorAnimationEnabled" const val DELETE_EMPTY_LINES = "idepref_editor_deleteEmptyLines" const val DELETE_TABS_ON_BACKSPACE = "idepref_editor_deleteTab" const val STICKY_SCROLL_ENABLED = "idepref_editor_stickyScrollEnabled" @@ -147,6 +148,12 @@ object EditorPreferences { prefManager.putBoolean(USE_CUSTOM_FONT, value) } + var cursorAnimationEnabled: Boolean + get() = prefManager.getBoolean(CURSOR_ANIMATION_ENABLED, false) + set(value) { + prefManager.putBoolean(CURSOR_ANIMATION_ENABLED, value) + } + var colorScheme: String get() = prefManager.getString(COLOR_SCHEME, DEFAULT_COLOR_SCHEME) set(value) {