Skip to content

Commit

Permalink
feat: add preference to disable editor cursor animation
Browse files Browse the repository at this point in the history
  • Loading branch information
teixeira0x committed Dec 12, 2024
1 parent 27681db commit b9f8d58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +87,7 @@ private class CommonConfigurations(
addPreference(VisibiblePasswordFlag())
addPreference(DeleteEmptyLines())
addPreference(DeleteTabs())
addPreference(CursorAnimationEnabled())
addPreference(StickyScrollEnabled())
addPreference(PinLineNumbersEnabled())
addPreference(CompletionsMatchLower())
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class CodeEditorView(
onUseIcuPrefChanged()
onDeleteEmptyLinesPrefChanged()
onDeleteTabsPrefChanged()
onCursorAnimationPrefChanged()
onStickyScrollEnabeldPrefChanged()
onPinLineNumbersPrefChanged()
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions core/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@
<string name="msg_swipe_for_output">Swipe up for @@build output@@.</string>
<string name="idepref_editor_useSoftTabs_title">Use soft tab</string>
<string name="idepref_editor_useSoftTabs_summary">Choose whether to use spaces instead of tab character (\\t).</string>
<string name="idepref_editor_cursorAnimationEnabled_title">Enable cursor animation</string>
<string name="idepref_editor_cursorAnimationEnabled_summary">Choose whether to use animation when moving the cursor.</string>
<string name="btn_donate">Donate</string>
<string name="btn_docs">Documentation</string>
<string name="btn_close">Close</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b9f8d58

Please sign in to comment.