Skip to content

Commit

Permalink
Add keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
billthefarmer committed Feb 19, 2024
1 parent fe1606b commit 96e2f1b
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions src/main/java/org/billthefarmer/editor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ public class Editor extends Activity
private Runnable updateWordCount;

private ScaleGestureDetector scaleDetector;
private QueryTextListener queryTextListener;

private Map<String, Integer> pathMap;
private List<String> removeList;
Expand Down Expand Up @@ -615,8 +616,8 @@ else if (text != null)
// setListeners
private void setListeners()
{
scaleDetector =
new ScaleGestureDetector(this, new ScaleListener());
scaleDetector = new ScaleGestureDetector(this, new ScaleListener());
queryTextListener = new QueryTextListener();

if (textView != null)
{
Expand Down Expand Up @@ -884,7 +885,7 @@ public boolean onPrepareOptionsMenu(Menu menu)
{
searchView.setSubmitButtonEnabled(true);
searchView.setImeOptions(EditorInfo.IME_ACTION_GO);
searchView.setOnQueryTextListener(new QueryTextListener());
searchView.setOnQueryTextListener(queryTextListener);
}

// Show find all item
Expand Down Expand Up @@ -1185,6 +1186,7 @@ public boolean dispatchTouchEvent(MotionEvent event)
return super.dispatchTouchEvent(event);
}

// onKeyDown
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
Expand All @@ -1207,6 +1209,10 @@ public boolean onKeyDown(int keyCode, KeyEvent event)
else
searchItem.expandActionView();
break;
// Goto
case KeyEvent.KEYCODE_G:
goTo();
break;
// New
case KeyEvent.KEYCODE_N:
newFile();
Expand All @@ -1215,13 +1221,29 @@ public boolean onKeyDown(int keyCode, KeyEvent event)
case KeyEvent.KEYCODE_O:
openFile();
break;
// Print
case KeyEvent.KEYCODE_P:
print();
break;
// Save, Save as
case KeyEvent.KEYCODE_S:
if (event.isShiftPressed())
saveAs();
else
saveCheck();
break;
// Increase text size
case KeyEvent.KEYCODE_PLUS:
size += 2;
size = Math.max(TINY, Math.min(size, HUGE));
textView.setTextSize(size);
break;
// Decrease text size
case KeyEvent.KEYCODE_MINUS:
size += 2;
size = Math.max(TINY, Math.min(size, HUGE));
textView.setTextSize(size);
break;

default:
return super.onKeyDown(keyCode, event);
Expand All @@ -1230,6 +1252,22 @@ public boolean onKeyDown(int keyCode, KeyEvent event)
return true;
}

else
{
switch (keyCode)
{
// Find next
case KeyEvent.KEYCODE_F3:
if (searchItem.isActionViewExpanded())
queryTextListener.onQueryTextSubmit
(searchView.getQuery().toString());
break;
// Menu
case KeyEvent.KEYCODE_F10:
openOptionsMenu();
}
}

return super.onKeyDown(keyCode, event);
}

Expand Down

0 comments on commit 96e2f1b

Please sign in to comment.