Skip to content

Commit

Permalink
Fix CB discarding changes if pressed Ctrl + Enter too quickly (#6875)
Browse files Browse the repository at this point in the history
Now, quick typing in component browser and pressing "enter" should not cut off the last part typed. Fixes #6733

https://github.com/enso-org/enso/assets/3919101/3979ed5a-ba4e-4e25-93e6-672e731b7bd8

On this occasion, also fixed "go-to-dashboard" button and "Unsupported engine version" being over the full-screen visualization. Fixes #6722

# Important Notes
I did a significant refactoring of Project View:
1. The huge `frp::extend` block was split into multiple `init` methods.
2. Remaining of the "Old searcher" were removed.
3. The "Edited" event from node's input is emitted only when in edit mode (it's consistent with other API terminology, and makes FRP for showing CB much simpler.

The code was _mostly_ moved around, but the check is advised anyway, as there were small changes here and there.
  • Loading branch information
farmaazon authored Jun 1, 2023
1 parent ed3f9b3 commit 2e39d75
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 219 deletions.
10 changes: 5 additions & 5 deletions app/gui/src/controller/searcher/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ pub enum MatchKind {
/// The entry's label to be displayed in the component browser was matched.
#[default]
Label,
/// The code to be generated by the entry was matched.
Code,
/// The entry's name from the code was matched.
Name,
/// An alias of the entry was matched, contains the specific alias that was matched.
Alias(ImString),
}
Expand Down Expand Up @@ -204,7 +204,7 @@ impl ListEntry {
fuzzly::find_best_subsequence(self.action.to_string(), pattern, metric)
});
self.match_info = match subsequence {
Some(subsequence) => MatchInfo::Matches { subsequence, kind: MatchKind::Code },
Some(subsequence) => MatchInfo::Matches { subsequence, kind: MatchKind::Label },
None => MatchInfo::DoesNotMatch,
};
}
Expand Down Expand Up @@ -442,7 +442,7 @@ impl<'a> CategoryBuilder<'a> {
let category = self.category_id;
built_list.entries.borrow_mut().extend(iter.into_iter().map(|action| {
let match_info =
MatchInfo::Matches { subsequence: default(), kind: MatchKind::Code };
MatchInfo::Matches { subsequence: default(), kind: MatchKind::Label };
ListEntry { category, match_info, action }
}));
}
Expand Down Expand Up @@ -497,7 +497,7 @@ impl ListWithSearchResultBuilder {
.iter()
.map(|entry| {
let match_info =
MatchInfo::Matches { subsequence: default(), kind: MatchKind::Code };
MatchInfo::Matches { subsequence: default(), kind: MatchKind::Label };
let action = entry.action.clone_ref();
let category = self.search_result_category;
ListEntry { category, match_info, action }
Expand Down
28 changes: 12 additions & 16 deletions app/gui/src/controller/searcher/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,36 +176,32 @@ impl Component {
pub fn update_matching_info(&self, filter: Filter) {
// Match the input pattern to the component label.
let label = self.to_string();
let label_matches = fuzzly::matches(&label, filter.pattern.clone_ref());
let label_matches = fuzzly::matches(&label, filter.pattern.as_str());
let label_subsequence = label_matches.and_option_from(|| {
let metric = fuzzly::metric::default();
fuzzly::find_best_subsequence(label, filter.pattern.clone_ref(), metric)
fuzzly::find_best_subsequence(label, filter.pattern.as_str(), metric)
});
let label_match_info = label_subsequence
.map(|subsequence| MatchInfo::Matches { subsequence, kind: MatchKind::Label });

// Match the input pattern to the code to be inserted.
let in_module = QualifiedName::as_ref(&filter.module_name);
let code = match &self.data {
Data::FromDatabase { entry, .. } => entry.code_to_insert(true, in_module).to_string(),
Data::Virtual { snippet } => snippet.code.to_string(),
};
let code_matches = fuzzly::matches(&code, filter.pattern.clone_ref());
let code_subsequence = code_matches.and_option_from(|| {
// Match the input pattern to the component name.
let name = self.name();
let name_matches = fuzzly::matches(name, filter.pattern.as_str());
let name_subsequence = name_matches.and_option_from(|| {
let metric = fuzzly::metric::default();
fuzzly::find_best_subsequence(code, filter.pattern.clone_ref(), metric)
fuzzly::find_best_subsequence(name, filter.pattern.as_str(), metric)
});
let code_match_info = code_subsequence.map(|subsequence| {
let name_match_info = name_subsequence.map(|subsequence| {
let subsequence = fuzzly::Subsequence { indices: Vec::new(), ..subsequence };
MatchInfo::Matches { subsequence, kind: MatchKind::Code }
MatchInfo::Matches { subsequence, kind: MatchKind::Name }
});

// Match the input pattern to an entry's aliases and select the best alias match.
let alias_matches = self.aliases().filter_map(|alias| {
if fuzzly::matches(alias, filter.pattern.clone_ref()) {
if fuzzly::matches(alias, filter.pattern.as_str()) {
let metric = fuzzly::metric::default();
let subsequence =
fuzzly::find_best_subsequence(alias, filter.pattern.clone_ref(), metric);
fuzzly::find_best_subsequence(alias, filter.pattern.as_str(), metric);
subsequence.map(|subsequence| (subsequence, alias))
} else {
None
Expand All @@ -221,7 +217,7 @@ impl Component {
});

// Select the best match of the available label-, code- and alias matches.
let match_info_iter = [alias_match_info, code_match_info, label_match_info].into_iter();
let match_info_iter = [alias_match_info, name_match_info, label_match_info].into_iter();
let best_match_info = match_info_iter.flatten().max_by(|lhs, rhs| lhs.cmp(rhs));
*self.match_info.borrow_mut() = best_match_info.unwrap_or(MatchInfo::DoesNotMatch);

Expand Down
10 changes: 6 additions & 4 deletions app/gui/view/graph-editor/src/component/node/input/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ ensogl::define_endpoints! {
Output {
pointer_style (cursor::Style),
width (f32),
/// Changes done when nodes is in edit mode.
expression_edit (ImString, Vec<Selection<Byte>>),

editing (bool),
Expand Down Expand Up @@ -477,17 +478,18 @@ impl Area {
legit_edit <- frp.input.edit_expression.gate(&set_editing);
model.edit_mode_label.select <+ legit_edit.map(|(range, _)| (range.start.into(), range.end.into()));
model.edit_mode_label.insert <+ legit_edit._1();
expression_changed_by_user <- model.edit_mode_label.content.gate(&set_editing);
frp.output.source.expression_edit <+ model.edit_mode_label.selections.map2(
&expression_changed_by_user,
expression_edited <- model.edit_mode_label.content.gate(&set_editing);
selections_edited <- model.edit_mode_label.selections.gate(&set_editing);
frp.output.source.expression_edit <+ selections_edited.gate(&set_editing).map2(
&model.edit_mode_label.content,
f!([model](selection, full_content) {
let full_content = full_content.into();
let to_byte = |loc| text::Byte::from_in_context_snapped(&model.edit_mode_label, loc);
let selections = selection.iter().map(|sel| sel.map(to_byte)).collect_vec();
(full_content, selections)
})
);
frp.output.source.on_port_code_update <+ expression_changed_by_user.map(|e| {
frp.output.source.on_port_code_update <+ expression_edited.map(|e| {
// Treat edit mode update as a code modification at the span tree root.
(default(), e.into())
});
Expand Down
Loading

0 comments on commit 2e39d75

Please sign in to comment.