Skip to content

Commit

Permalink
Fixed tab triggering browser tab in emscripten/web.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtytel committed Feb 5, 2025
1 parent 29e6495 commit d09f1be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions visage_widgets/text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ namespace visage {
return key.modifierMask() == 0 || key.modifierMask() == kModifierShift;
}

bool TextEditor::keyRelease(const KeyEvent& key) {
return active_;
}

String TextEditor::translateDeadKeyText(const String& text) const {
if (text.length() != 1 || dead_key_entry_ == DeadKey::None)
return text;
Expand Down
2 changes: 2 additions & 0 deletions visage_widgets/text_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace visage {
void tripleClick(const MouseEvent& e);
bool handleDeadKey(const KeyEvent& key);
bool keyPress(const KeyEvent& key) override;
bool keyRelease(const KeyEvent& key) override;
bool receivesTextInput() override { return active_; }
String translateDeadKeyText(const String& text) const;
void textInput(const std::string& text) override;
Expand Down Expand Up @@ -224,6 +225,7 @@ namespace visage {
void setBackgroundColorId(int color_id) { background_color_id_ = color_id; }

private:
bool processKeyPress(const KeyEvent& key);
void addUndoPosition() { undo_history_.emplace_back(text_.text(), caret_position_); }

CallbackList<void()> on_text_change_;
Expand Down
6 changes: 4 additions & 2 deletions visage_windowing/emscripten/windowing_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,13 @@ namespace visage {
return false;

bool down_used = window->handleKeyDown(code, modifier_state, event->repeat);
return modifier_state != 0 && modifier_state != kModifierShift && down_used;
bool text_input = modifier_state == 0 || modifier_state == kModifierShift;
return (code == KeyCode::Tab || !text_input) && down_used;
}
case EMSCRIPTEN_EVENT_KEYUP: {
bool up_used = window->handleKeyUp(code, modifier_state);
return modifier_state != 0 && modifier_state != kModifierShift && up_used;
bool text_input = modifier_state == 0 || modifier_state == kModifierShift;
return (code == KeyCode::Tab || !text_input) && up_used;
}
default: return false;
}
Expand Down

0 comments on commit d09f1be

Please sign in to comment.