Skip to content

Commit fb48eec

Browse files
committed
feat: add notepad edit subcommand
1 parent fb2fcaa commit fb48eec

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

app/src/main/java/com/coderGtm/yantra/commands/notepad/Command.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ class Command(terminal: Terminal) : BaseCommand(terminal) {
7575
}
7676
return
7777
}
78+
if (action == "edit") {
79+
if (notes.contains(name)) {
80+
YantraLauncherDialog(terminal.activity).takeInput(
81+
title = terminal.activity.getString(R.string.edit_note, name),
82+
message = terminal.activity.getString(R.string.enter_note_content),
83+
cancellable = false,
84+
inputType = InputType.TYPE_TEXT_FLAG_MULTI_LINE,
85+
initialInput = terminal.preferenceObject.getString("notepad_note_${name}", "") ?: "",
86+
positiveButton = terminal.activity.getString(R.string.save),
87+
positiveAction = {
88+
val note_text = it.trim()
89+
terminal.preferenceObject.edit().putString("notepad_note_${name}", note_text).apply()
90+
output(terminal.activity.getString(R.string.note_saved_to_notepad, name), terminal.theme.successTextColor)
91+
}
92+
)
93+
} else {
94+
output(terminal.activity.getString(R.string.no_note_fond_by_the_name, name), terminal.theme.errorTextColor)
95+
}
96+
return
97+
}
7898
if (action == "delete") {
7999
if (notes.contains(name)) {
80100
terminal.preferenceObject.edit().remove("notepad_note_${name}").apply()

app/src/main/java/com/coderGtm/yantra/terminal/Helper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fun showSuggestions(
332332
overrideLastWord = true
333333
}
334334
val regex = Regex(Pattern.quote(input.removePrefix(args[0]).trim()), RegexOption.IGNORE_CASE)
335-
val notepadArgs = listOf("list","read","new","delete")
335+
val notepadArgs = listOf("list","read","new","edit","delete")
336336
for (arg in notepadArgs) {
337337
if (regex.containsMatchIn(arg)) {
338338
suggestions.add(arg)

0 commit comments

Comments
 (0)