mirror of
https://github.com/enso-org/enso.git
synced 2024-12-25 14:05:40 +03:00
Fixed textfield key masking on Mac (https://github.com/enso-org/ide/pull/552)
Original commit: 63ad62cf3d
This commit is contained in:
parent
b1e629716a
commit
b8756cd60e
2
gui/.github/workflows/build.yml
vendored
2
gui/.github/workflows/build.yml
vendored
@ -35,7 +35,7 @@ jobs:
|
|||||||
- name: Install Node
|
- name: Install Node
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12.16.1'
|
node-version: '12.18.0'
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: node ./run dist
|
run: node ./run dist
|
||||||
|
12
gui/.github/workflows/check.yml
vendored
12
gui/.github/workflows/check.yml
vendored
@ -48,7 +48,7 @@ jobs:
|
|||||||
- name: Install Node
|
- name: Install Node
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12.16.1'
|
node-version: '12.18.0'
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: node ./run build
|
run: node ./run build
|
||||||
@ -86,7 +86,7 @@ jobs:
|
|||||||
- name: Install Node
|
- name: Install Node
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12.16.1'
|
node-version: '12.18.0'
|
||||||
|
|
||||||
- name: Building Rust Sources
|
- name: Building Rust Sources
|
||||||
run: node ./run lint
|
run: node ./run lint
|
||||||
@ -121,7 +121,7 @@ jobs:
|
|||||||
- name: Install Node
|
- name: Install Node
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12.16.1'
|
node-version: '12.18.0'
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: node ./run test --no-wasm
|
run: node ./run test --no-wasm
|
||||||
@ -168,7 +168,7 @@ jobs:
|
|||||||
- name: Install Node
|
- name: Install Node
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12.16.1'
|
node-version: '12.18.0'
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: node ./run test --no-native
|
run: node ./run test --no-native
|
||||||
@ -190,7 +190,7 @@ jobs:
|
|||||||
# - name: Install Node
|
# - name: Install Node
|
||||||
# uses: actions/setup-node@v1
|
# uses: actions/setup-node@v1
|
||||||
# with:
|
# with:
|
||||||
# node-version: '12.16.1'
|
# node-version: '12.18.0'
|
||||||
#
|
#
|
||||||
# - name: Generate test profile
|
# - name: Generate test profile
|
||||||
# working-directory: src/rust
|
# working-directory: src/rust
|
||||||
@ -210,4 +210,4 @@ jobs:
|
|||||||
# uses: codecov/codecov-action@v1.0.2
|
# uses: codecov/codecov-action@v1.0.2
|
||||||
# with:
|
# with:
|
||||||
# token: ${{ secrets.CODECOV_TOKEN }}
|
# token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
# file: ./lcov.info
|
# file: ./lcov.info
|
||||||
|
4
gui/run
4
gui/run
@ -12,8 +12,8 @@ let args = process.argv.slice(2)
|
|||||||
let no_validation = '--no-validation'
|
let no_validation = '--no-validation'
|
||||||
async function init () {
|
async function init () {
|
||||||
if(!args.includes(no_validation)) {
|
if(!args.includes(no_validation)) {
|
||||||
await cmd.check_version('npm','6.13.4',{silent:true})
|
await cmd.check_version('npm','6.14.4',{silent:true})
|
||||||
await cmd.check_version('node','v12.16.1',{silent:true})
|
await cmd.check_version('node','v12.18.0',{silent:true})
|
||||||
await cmd.check_version('rustc','1.40.0-nightly',{
|
await cmd.check_version('rustc','1.40.0-nightly',{
|
||||||
preprocess:(v)=>v.substring(6,20),silent:true
|
preprocess:(v)=>v.substring(6,20),silent:true
|
||||||
})
|
})
|
||||||
|
@ -133,16 +133,23 @@ impl TextFieldKeyboardFrp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn enables_writing(mask:&keyboard::KeyMask) -> bool {
|
||||||
|
let modifiers = &[keyboard::Key::Control,keyboard::Key::Alt,keyboard::Key::Meta];
|
||||||
|
let is_modifier = modifiers.iter().any(|key| mask.contains(key));
|
||||||
|
let is_alt_graph = mask.contains(&keyboard::Key::AltGraph);
|
||||||
|
match Platform::query() {
|
||||||
|
// On Windows AltGraph is emitted as both AltGraph and Ctrl. Therefore we don't
|
||||||
|
// care about modifiers when AltGraph is pressed.
|
||||||
|
Platform::Windows => !is_modifier || is_alt_graph,
|
||||||
|
_ => !is_modifier
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn char_typed_lambda(text_field:WeakTextField) -> impl Fn(&keyboard::Key,&keyboard::KeyMask) {
|
fn char_typed_lambda(text_field:WeakTextField) -> impl Fn(&keyboard::Key,&keyboard::KeyMask) {
|
||||||
move |key,mask| {
|
move |key,mask| {
|
||||||
text_field.upgrade().for_each(|text_field| {
|
text_field.upgrade().for_each(|text_field| {
|
||||||
if let keyboard::Key::Character(string) = key {
|
if let keyboard::Key::Character(string) = key {
|
||||||
let modifiers = &[keyboard::Key::Control,keyboard::Key::Alt];
|
if Self::enables_writing(mask) {
|
||||||
let is_modifier = modifiers.iter().any(|key| mask.contains(key));
|
|
||||||
let is_alt_graph = mask.contains(&keyboard::Key::AltGraph);
|
|
||||||
// On Windows AltGraph is emitted as both AltGraph and Ctrl. Therefore we don't
|
|
||||||
// care about modifiers when AltGraph is pressed.
|
|
||||||
if !is_modifier || is_alt_graph {
|
|
||||||
text_field.write(string);
|
text_field.write(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ use ensogl::display::shape::text::text_field::TextField;
|
|||||||
use ensogl::display::shape::text::text_field::TextFieldProperties;
|
use ensogl::display::shape::text::text_field::TextFieldProperties;
|
||||||
use ensogl::display::world::*;
|
use ensogl::display::world::*;
|
||||||
use ensogl::display;
|
use ensogl::display;
|
||||||
|
use ensogl::system::web::platform::Platform;
|
||||||
use nalgebra::Vector2;
|
use nalgebra::Vector2;
|
||||||
use nalgebra::zero;
|
use nalgebra::zero;
|
||||||
use utils::channel::process_stream_with_handle;
|
use utils::channel::process_stream_with_handle;
|
||||||
@ -88,8 +89,16 @@ impl TextEditor {
|
|||||||
Self::new_from_data(data).initialize(keyboard_actions)
|
Self::new_from_data(data).initialize(keyboard_actions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_save_keys_mask() -> KeyMask {
|
||||||
|
if let Platform::MacOS = Platform::query() {
|
||||||
|
KeyMask::meta_plus('s')
|
||||||
|
} else {
|
||||||
|
KeyMask::control_plus('s')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn initialize(self, keyboard_actions:&mut keyboard::Actions) -> Self {
|
fn initialize(self, keyboard_actions:&mut keyboard::Actions) -> Self {
|
||||||
let save_keys = KeyMask::control_plus('s');
|
let save_keys = Self::get_save_keys_mask();
|
||||||
let text_editor = Rc::downgrade(&self.rc);
|
let text_editor = Rc::downgrade(&self.rc);
|
||||||
keyboard_actions.add_action_for_key_mask(save_keys,enclose!((text_editor) move || {
|
keyboard_actions.add_action_for_key_mask(save_keys,enclose!((text_editor) move || {
|
||||||
if let Some(text_editor) = text_editor.upgrade() {
|
if let Some(text_editor) = text_editor.upgrade() {
|
||||||
|
@ -31,6 +31,11 @@ pub use keyboard_types::Key;
|
|||||||
pub struct KeyMask(pub BitField256);
|
pub struct KeyMask(pub BitField256);
|
||||||
|
|
||||||
impl KeyMask {
|
impl KeyMask {
|
||||||
|
/// Creates Key::Meta + Key::Character.
|
||||||
|
pub fn meta_plus(character:char) -> Self {
|
||||||
|
Self::from_vec(vec![Key::Meta, Key::Character(character.to_string())])
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates Key::Control + Key::Character.
|
/// Creates Key::Control + Key::Character.
|
||||||
pub fn control_plus(character:char) -> Self {
|
pub fn control_plus(character:char) -> Self {
|
||||||
Self::from_vec(vec![Key::Control, Key::Character(character.to_string())])
|
Self::from_vec(vec![Key::Control, Key::Character(character.to_string())])
|
||||||
|
Loading…
Reference in New Issue
Block a user