-
Notifications
You must be signed in to change notification settings - Fork 4
Implement smart delete #55
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
Changes from 12 commits
d7304a4
d052d91
f28d15b
4592f0f
39f7878
851025d
dd89252
e21b969
0b363e2
9e37b97
3fb6225
ed05f14
36e343f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||
| package com.rickyhu.hushkeyboard.settings.ui | ||||||
|
|
||||||
| import androidx.compose.foundation.clickable | ||||||
| import androidx.compose.material3.Icon | ||||||
| import androidx.compose.material3.ListItem | ||||||
| import androidx.compose.material3.Switch | ||||||
| import androidx.compose.material3.Text | ||||||
| import androidx.compose.runtime.Composable | ||||||
| import androidx.compose.ui.Modifier | ||||||
| import androidx.compose.ui.platform.testTag | ||||||
| import androidx.compose.ui.res.painterResource | ||||||
| import androidx.compose.ui.tooling.preview.Preview | ||||||
| import com.rickyhu.hushkeyboard.R | ||||||
| import com.rickyhu.hushkeyboard.theme.HushKeyboardTheme | ||||||
|
|
||||||
| @Composable | ||||||
| fun SmartDeleteSwitchItem( | ||||||
| value: Boolean, | ||||||
| onValueChanged: (Boolean) -> Unit = {} | ||||||
| ) { | ||||||
| ListItem( | ||||||
| modifier = Modifier.clickable { onValueChanged(!value) }, | ||||||
| headlineContent = { Text("Smart Delete") }, | ||||||
| leadingContent = { | ||||||
| Icon( | ||||||
| painter = painterResource(R.drawable.ic_backspace_filled), | ||||||
| contentDescription = "Delete" | ||||||
| ) | ||||||
| }, | ||||||
| trailingContent = { | ||||||
| Switch( | ||||||
| checked = value, | ||||||
| onCheckedChange = onValueChanged, | ||||||
| modifier = Modifier.testTag("SmartDeleteSwitchItem") | ||||||
| ) | ||||||
| } | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| @Preview(showBackground = true) | ||||||
| @Composable | ||||||
| fun SmartDeleteSwitchItemPreview() { | ||||||
| HushKeyboardTheme { | ||||||
| AddSpaceBetweenNotationSwitchItem( | ||||||
|
||||||
| AddSpaceBetweenNotationSwitchItem( | |
| SmartDeleteSwitchItem( |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,23 +1,68 @@ | ||||||||||||
| package com.rickyhu.hushkeyboard.utils | ||||||||||||
|
|
||||||||||||
| import android.content.Context | ||||||||||||
| import android.util.Log | ||||||||||||
| import android.view.inputmethod.InputConnection | ||||||||||||
| import com.rickyhu.hushkeyboard.model.Notation | ||||||||||||
| import com.rickyhu.hushkeyboard.service.HushIMEService | ||||||||||||
|
|
||||||||||||
| private const val CURSOR_POSITION = 1 | ||||||||||||
| private const val TAG = "InputConnection" | ||||||||||||
| private const val END_CURSOR_POSITION = 1 | ||||||||||||
|
|
||||||||||||
| val notationCharList = Notation.getCharList() + listOf('\n') | ||||||||||||
|
|
||||||||||||
|
||||||||||||
| val notationCharList = Notation.getCharList() + listOf('\n') | |
| // Newline character is included to handle smart delete functionality, allowing deletion of line breaks. | |
| private const val NEWLINE_CHAR = '\n' | |
| val notationCharList = Notation.getCharList() + listOf(NEWLINE_CHAR) |
Outdated
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 50 for scan window size should be extracted to a named constant to improve code maintainability and make it easier to adjust if needed.
| val scanWindow = 50 | |
| val scanWindow = SCAN_WINDOW_SIZE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> | ||
|
|
||
| <path android:fillColor="@android:color/white" android:pathData="M22,3L7,3c-0.69,0 -1.23,0.35 -1.59,0.88L0,12l5.41,8.11c0.36,0.53 0.9,0.89 1.59,0.89h15c1.1,0 2,-0.9 2,-2L24,5c0,-1.1 -0.9,-2 -2,-2zM19,15.59L17.59,17 14,13.41 10.41,17 9,15.59 12.59,12 9,8.41 10.41,7 14,10.59 17.59,7 19,8.41 15.41,12 19,15.59z"/> | ||
|
|
||
| </vector> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> | ||
|
|
||
| <path android:fillColor="@android:color/white" android:pathData="M22,3L7,3c-0.69,0 -1.23,0.35 -1.59,0.88L0,12l5.41,8.11c0.36,0.53 0.9,0.89 1.59,0.89h15c1.1,0 2,-0.9 2,-2L24,5c0,-1.1 -0.9,-2 -2,-2zM22,19L7.07,19L2.4,12l4.66,-7L22,5v14zM10.41,17L14,13.41 17.59,17 19,15.59 15.41,12 19,8.41 17.59,7 14,10.59 10.41,7 9,8.41 12.59,12 9,15.59z"/> | ||
|
|
||
| </vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log message says "Smart delete button tapped" when this is actually the regular delete functionality (when smart delete is disabled). This should be "Delete button tapped" to match the actual functionality.