Skip to content

Commit

Permalink
TextView:Cmd/Ctrl-Home/End Shift-selection support
Browse files Browse the repository at this point in the history
Fixes #6859

Signed-off-by: Siarzhuk Zharski <zharik@gmx.li>
  • Loading branch information
przemub authored and siarzhuk committed Jan 14, 2013
1 parent 075d3e6 commit dc871e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions headers/os/interface/TextView.h
Expand Up @@ -455,6 +455,8 @@ class BTextView : public BView {
int32 fLastClickOffset;
bool fInstalledNavigateWordwiseShortcuts;
bool fInstalledNavigateToTopOrBottomShortcuts;
bool fInstalledSelectWordwiseShortcuts;
bool fInstalledSelectToTopOrBottomShortcuts;

uint32 _reserved[6];
};
Expand Down
41 changes: 39 additions & 2 deletions src/kits/interface/TextView.cpp
Expand Up @@ -3343,6 +3343,8 @@ BTextView::_InitObject(BRect textRect, const BFont *initialFont,

fInstalledNavigateWordwiseShortcuts = false;
fInstalledNavigateToTopOrBottomShortcuts = false;
fInstalledSelectWordwiseShortcuts = false;
fInstalledSelectToTopOrBottomShortcuts = false;

// We put these here instead of in the constructor initializer list
// to have less code duplication, and a single place where to do changes
Expand Down Expand Up @@ -3619,6 +3621,7 @@ BTextView::_HandlePageKey(uint32 inPageKey, bool commandKeyDown)
currentMessage->FindInt32("modifiers", &mods);

bool shiftDown = mods & B_SHIFT_KEY;
bool controlDown = mods & B_CONTROL_KEY;
STELine* line = NULL;
int32 selStart = fSelStart;
int32 selEnd = fSelEnd;
Expand All @@ -3631,7 +3634,7 @@ BTextView::_HandlePageKey(uint32 inPageKey, bool commandKeyDown)
break;
}

if (commandKeyDown) {
if (commandKeyDown || controlDown) {
_ScrollTo(0, 0);
fCaretOffset = 0;
} else {
Expand Down Expand Up @@ -3664,7 +3667,7 @@ BTextView::_HandlePageKey(uint32 inPageKey, bool commandKeyDown)
break;
}

if (commandKeyDown) {
if (commandKeyDown || controlDown) {
_ScrollTo(0, fTextRect.bottom + fLayoutData->bottomInset);
fCaretOffset = fText->Length();
} else {
Expand Down Expand Up @@ -5178,6 +5181,18 @@ BTextView::_Activate()
new BMessage(NAVIGATE_TO_NEXT_WORD), this);
fInstalledNavigateWordwiseShortcuts = true;
}
if (!Window()->HasShortcut(B_LEFT_ARROW, B_COMMAND_KEY | B_SHIFT_KEY)
&& !Window()->HasShortcut(B_RIGHT_ARROW, B_COMMAND_KEY | B_SHIFT_KEY)) {
BMessage* message = new BMessage(NAVIGATE_TO_PREVIOUS_WORD);
message->AddInt32("modifiers", B_SHIFT_KEY);
Window()->AddShortcut(B_LEFT_ARROW, B_COMMAND_KEY | B_SHIFT_KEY,
message, this);
message = new BMessage(NAVIGATE_TO_NEXT_WORD);
message->AddInt32("modifiers", B_SHIFT_KEY);
Window()->AddShortcut(B_RIGHT_ARROW, B_COMMAND_KEY | B_SHIFT_KEY,
message, this);
fInstalledSelectWordwiseShortcuts = true;
}
if (!Window()->HasShortcut(B_HOME, B_COMMAND_KEY)
&& !Window()->HasShortcut(B_END, B_COMMAND_KEY)) {
Window()->AddShortcut(B_HOME, B_COMMAND_KEY,
Expand All @@ -5186,6 +5201,18 @@ BTextView::_Activate()
new BMessage(NAVIGATE_TO_BOTTOM), this);
fInstalledNavigateToTopOrBottomShortcuts = true;
}
if (!Window()->HasShortcut(B_HOME, B_COMMAND_KEY | B_SHIFT_KEY)
&& !Window()->HasShortcut(B_END, B_COMMAND_KEY | B_SHIFT_KEY)) {
BMessage* message = new BMessage(NAVIGATE_TO_TOP);
message->AddInt32("modifiers", B_SHIFT_KEY);
Window()->AddShortcut(B_HOME, B_COMMAND_KEY | B_SHIFT_KEY,
message, this);
message = new BMessage(NAVIGATE_TO_BOTTOM);
message->AddInt32("modifiers", B_SHIFT_KEY);
Window()->AddShortcut(B_END, B_COMMAND_KEY | B_SHIFT_KEY,
message, this);
fInstalledSelectToTopOrBottomShortcuts = true;
}
}
}

Expand All @@ -5212,11 +5239,21 @@ BTextView::_Deactivate()
Window()->RemoveShortcut(B_RIGHT_ARROW, B_COMMAND_KEY);
fInstalledNavigateWordwiseShortcuts = false;
}
if (fInstalledSelectWordwiseShortcuts) {
Window()->RemoveShortcut(B_LEFT_ARROW, B_COMMAND_KEY | B_SHIFT_KEY);
Window()->RemoveShortcut(B_RIGHT_ARROW, B_COMMAND_KEY | B_SHIFT_KEY);
fInstalledSelectWordwiseShortcuts = false;
}
if (fInstalledNavigateToTopOrBottomShortcuts) {
Window()->RemoveShortcut(B_HOME, B_COMMAND_KEY);
Window()->RemoveShortcut(B_END, B_COMMAND_KEY);
fInstalledNavigateToTopOrBottomShortcuts = false;
}
if (fInstalledSelectToTopOrBottomShortcuts) {
Window()->RemoveShortcut(B_HOME, B_COMMAND_KEY | B_SHIFT_KEY);
Window()->RemoveShortcut(B_END, B_COMMAND_KEY | B_SHIFT_KEY);
fInstalledSelectToTopOrBottomShortcuts = false;
}
}
}

Expand Down

0 comments on commit dc871e3

Please sign in to comment.