added filtering to text pasted to EditableWidget

updated doc for UI keys (TODO: UI edit keys)
This commit is contained in:
thrust26 2020-11-05 15:19:33 +01:00
parent 899584b455
commit 7ef46b366d
2 changed files with 147 additions and 10 deletions

View File

@ -1364,8 +1364,8 @@
</tr>
<tr>
<td>Toggle windowed/fullscreen mode</td>
<td>Alt + Enter</td>
<td>Cmd + Enter</td>
<td>Alt + Return</td>
<td>Cmd + Return</td>
</tr>
<tr>
<td>Toggle adapting display refresh rate to game frame rate
@ -1757,11 +1757,6 @@
<td>Backspace</td>
<td>Backspace</td>
</tr>
<tr>
<td>Go to parent directory (UI mode)</td>
<td>Backspace</td>
<td>Backspace</td>
</tr>
<tr>
<td><i>Decrease</i> emulation speed (disables 'Turbo' mode)</td>
<td>Shift-Control + s</td>
@ -1867,8 +1862,129 @@
</tr>
</table>
<p><b>UI Keys (can be remapped)</b></p>
<table BORDER=2 cellpadding=4>
<tr>
<th>Function</th>
<th>Key (Standard)</th>
<th>Key (macOS)</th>
</tr>
<tr>
<td>Move Up</td>
<td>Up arrow</td>
<td>Up arrow</td>
</tr>
<tr>
<td>Move Down</td>
<td>Down arrow</td>
<td>Down arrow</td>
</tr>
<tr>
<td>Move Left</td>
<td>Left arrow</td>
<td>Left arrow</td>
</tr>
<tr>
<td>Move Right</td>
<td>Right arrow</td>
<td>Right arrow</td>
</tr>
<tr>
<td>Move Home</td>
<td>Home</td>
<td>Home</td>
</tr>
<tr>
<td>Move End</td>
<td>End</td>
<td>End</td>
</tr>
<tr>
<td>Move Page Up</td>
<td>Page Up</td>
<td>Page Up</td>
</tr>
<tr>
<td>Move Page Down</td>
<td>Page Down</td>
<td>Page Down</td>
</tr>
<tr>
<td>OK</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>Cancel</td>
<td>Escape</td>
<td>Escape</td>
</tr>
<tr>
<td>Select item</td>
<td>Return/Enter/Space</td>
<td>Return/Enter/Space</td>
</tr>
<tr>
<td>Move to previous object</td>
<td>Shift + Tab</td>
<td>Shift + Tab</td>
</tr>
<tr>
<td>Move to next object</td>
<td>Tab</td>
<td>Tab</td>
</tr>
<tr>
<td>Move to previous tab</td>
<td>Shift-Control + Tab</td>
<td>Shift-Control + Tab</td>
</tr>
<tr>
<td>Move to next tab</td>
<td>Control + Tab</td>
<td>Control + Tab</td>
</tr>
<tr>
<td>Go to parent directory</td>
<td>Backspace</td>
<td>Backspace</td>
</tr>
<tr>
<td>Toggle windowed/fullscreen mode</td>
<td>Alt + Return</td>
<td>Cmd + Return</td>
</tr>
<tr>
<td>Exit emulator</td>
<td>Control + q</td>
<td>Cmd + q</td>
</tr>
</table>
<p><b>UI Keys in Text Editing areas (cannot be remapped)</b></p>
*** TODO!!! ***
<table BORDER=2 cellpadding=4>
<tr>
<th>Function</th>
<th>Key (Standard)</th>
<th>Key (macOS)</th>
</tr>
<tr>
<td>Move cursor to beginning of line</td>
<td>Home, Control + a</td>
<td>Home, Control + a</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</table>
</br>
<table BORDER=2 cellpadding=4>
<tr><th>Key</th><th>Editor Function</th></tr>
<tr><td>Home, Control + a</td><td>Move cursor to beginning of line</td></tr>
@ -1884,6 +2000,7 @@
<tr><td>Control + v, Shift + Insert</td><td>Paste clipboard contents</td></tr>
<tr><td>Control + x, Shift + Delete</td><td>Cut entire line to clipboard</td></tr>
</table>
</blockquote></br>
<h2><b><a name="ControlMap">Controller Map</a></b></h2>

View File

@ -187,6 +187,10 @@ bool EditableWidget::handleControlKeys(StellaKey key, StellaMod mod)
sendCommand(EditableWidget::kChangedCmd, key, _id);
break;
case KBDK_Z:
// TODO: undo
break;
case KBDK_LEFT:
handled = moveWord(-1, shift);
if(!shift)
@ -700,10 +704,26 @@ bool EditableWidget::pasteSelectedText()
instance().eventHandler().pasteText(pasted);
// remove the currently selected text
killSelectedText();
// insert paste text instead
_editString.insert(_caretPos, pasted);
// insert filtered paste text instead
ostringstream buf;
bool lastOk = true; // only one filler char per invalid character (block)
for(char c : pasted)
if(_filter(tolower(c)))
{
buf << c;
lastOk = true;
}
else
{
if(lastOk)
buf << '_';
lastOk = false;
}
_editString.insert(_caretPos, buf.str());
// position cursor at the end of pasted text
_caretPos += int(pasted.length());
_caretPos += int(buf.str().length());
return selected || !pasted.empty();
}