BWindow & WebPostive: Move TextView detection code

... from WebPositive to BWindow. This way every window will detect
Command+Arrows and send them to BTextView if a BTextView has focus
instead of just WebPositive.

https://www.freelists.org/post/haiku-development/Wordwise-jumping-with-CTRL-in-BTextView

This trick doesn't work in Vision though...

Fixes #9913
This commit is contained in:
John Scipione 2016-03-17 16:12:44 -07:00
parent 3c1bde87b6
commit b001655640
2 changed files with 12 additions and 15 deletions

View File

@ -707,21 +707,7 @@ BrowserWindow::DispatchMessage(BMessage* message, BHandler* target)
if ((message->what == B_KEY_DOWN || message->what == B_UNMAPPED_KEY_DOWN)
&& message->FindString("bytes", &bytes) == B_OK
&& message->FindInt32("modifiers", &modifierKeys) == B_OK) {
modifierKeys = (int32)((uint32)modifierKeys & kModifiers);
BTextView* textView = dynamic_cast<BTextView*>(CurrentFocus());
if (bytes[0] == B_LEFT_ARROW && modifierKeys == B_COMMAND_KEY) {
if (textView != NULL)
textView->KeyDown(bytes, modifierKeys);
else
PostMessage(GO_BACK);
return;
} else if (bytes[0] == B_RIGHT_ARROW && modifierKeys == B_COMMAND_KEY) {
if (textView != NULL)
textView->KeyDown(bytes, modifierKeys);
else
PostMessage(GO_FORWARD);
return;
} else if (bytes[0] == B_FUNCTION_KEY) {
if (bytes[0] == B_FUNCTION_KEY) {
// Some function key Firefox compatibility
int32 key;
if (message->FindInt32("key", &key) == B_OK) {

View File

@ -3803,6 +3803,17 @@ BWindow::_HandleKeyDown(BMessage* event)
return true;
}
// Send Command+Left and Command+Right to textview if it has focus
if (key == B_LEFT_ARROW || key == B_RIGHT_ARROW) {
// check key before doing expensive dynamic_cast
BTextView* textView = dynamic_cast<BTextView*>(CurrentFocus());
if (textView != NULL) {
textView->KeyDown(bytes, modifiers);
// eat the event
return true;
}
}
// Pretend that the user opened a menu, to give the subclass a
// chance to update it's menus. This may install new shortcuts,
// which is why we have to call it here, before trying to find