diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2011-09-20 15:28:55 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2011-09-20 15:31:09 +0200 |
| commit | b093947fcacf4664c8a642a436dbe82fdc37119c (patch) | |
| tree | 09623035472bc65ee54f513dd4ef2175e2bbb16f /main/src | |
| parent | ad2d3c138119a76db73c968bb838908bb0e48cd3 (diff) | |
| download | cgeo-b093947fcacf4664c8a642a436dbe82fdc37119c.zip cgeo-b093947fcacf4664c8a642a436dbe82fdc37119c.tar.gz cgeo-b093947fcacf4664c8a642a436dbe82fdc37119c.tar.bz2 | |
Insert signature after the cursor
When inserting the signature, either automatically or through the menu,
leave the cursor in front as the signature is supposed to be at the end.
This was suggested in issue #508.
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 6 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoinit.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeovisit.java | 13 |
3 files changed, 12 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 584d213..fc573a5 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -4698,8 +4698,10 @@ public class cgBase { * @param insertText * @param addSpace * add a space character, if there is no whitespace before the current cursor position + * @param moveCursor + * place the cursor after the inserted text */ - static void insertAtPosition(final EditText editText, String insertText, final boolean addSpace) { + static void insertAtPosition(final EditText editText, String insertText, final boolean addSpace, final boolean moveCursor) { int selectionStart = editText.getSelectionStart(); int selectionEnd = editText.getSelectionEnd(); int start = Math.min(selectionStart, selectionEnd); @@ -4711,7 +4713,7 @@ public class cgBase { } editText.getText().replace(start, end, insertText); - int newCursor = start + insertText.length(); + int newCursor = moveCursor ? start + insertText.length() : start; editText.setSelection(newCursor, newCursor); } } diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java index 10495ee..1412206 100644 --- a/main/src/cgeo/geocaching/cgeoinit.java +++ b/main/src/cgeo/geocaching/cgeoinit.java @@ -201,7 +201,7 @@ public class cgeoinit extends AbstractActivity { private boolean insertSignatureTemplate(final LogTemplate template) { EditText sig = (EditText) findViewById(R.id.signature); String insertText = "[" + template.getTemplateString() + "]"; - cgBase.insertAtPosition(sig, insertText, true); + cgBase.insertAtPosition(sig, insertText, true, true); return true; } diff --git a/main/src/cgeo/geocaching/cgeovisit.java b/main/src/cgeo/geocaching/cgeovisit.java index a4a0f71..3cba036 100644 --- a/main/src/cgeo/geocaching/cgeovisit.java +++ b/main/src/cgeo/geocaching/cgeovisit.java @@ -326,9 +326,9 @@ public class cgeovisit extends cgLogForm { EditText log = (EditText) findViewById(R.id.log); String content = log.getText().toString(); if (StringUtils.isNotBlank(content)) { - insertIntoLog("\n"); + insertIntoLog("\n", false); } - insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base, false)); + insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base, false), false); return true; } else if (id >= 10 && id <= 19) { rating = (id - 9) / 2.0; @@ -346,15 +346,15 @@ public class cgeovisit extends cgLogForm { LogTemplate template = LogTemplateProvider.getTemplate(id); if (template != null) { String newText = template.getValue(base, false); - insertIntoLog(newText); + insertIntoLog(newText, true); return true; } return false; } - private void insertIntoLog(String newText) { + private void insertIntoLog(String newText, final boolean moveCursor) { EditText log = (EditText) findViewById(R.id.log); - cgBase.insertAtPosition(log, newText, true); + cgBase.insertAtPosition(log, newText, true, moveCursor); } private static String ratingTextValue(final double rating) { @@ -508,7 +508,8 @@ public class cgeovisit extends cgLogForm { } else if (StringUtils.isNotBlank(settings.getSignature()) && settings.signatureAutoinsert && StringUtils.isBlank(((EditText) findViewById(R.id.log)).getText())) { - insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base, false)); + text = "\n" + LogTemplateProvider.applyTemplates(settings.getSignature(), base, false); + insertIntoLog(text, false); } if (types.contains(typeSelected) == false) { |
