mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-04 06:34:26 +00:00
Add ZED_SELECTED_TEXT variable to tasks (#8865)
Tasks are able to access a users selected text using the environment variable "ZED_SELECTED_TEXT". Release notes: - Added ZED_SELECTED_TEXT task variable which contains contents of selection
This commit is contained in:
parent
3a9ec906af
commit
4c9c9df730
1 changed files with 6 additions and 0 deletions
|
@ -114,9 +114,12 @@ fn task_context(
|
|||
.map(|worktree| worktree.read(cx).abs_path().to_string_lossy().to_string())
|
||||
});
|
||||
|
||||
let selected_text = buffer.read(cx).chars_for_range(selection_range).collect();
|
||||
|
||||
let mut env = HashMap::from_iter([
|
||||
("ZED_ROW".into(), row.to_string()),
|
||||
("ZED_COLUMN".into(), column.to_string()),
|
||||
("ZED_SELECTED_TEXT".into(), selected_text),
|
||||
]);
|
||||
if let Some(path) = current_file {
|
||||
env.insert("ZED_FILE".into(), path);
|
||||
|
@ -321,6 +324,7 @@ mod tests {
|
|||
("ZED_WORKTREE_ROOT".into(), "/dir".into()),
|
||||
("ZED_ROW".into(), "1".into()),
|
||||
("ZED_COLUMN".into(), "1".into()),
|
||||
("ZED_SELECTED_TEXT".into(), "".into())
|
||||
])
|
||||
}
|
||||
);
|
||||
|
@ -338,6 +342,7 @@ mod tests {
|
|||
("ZED_SYMBOL".into(), "this_is_a_rust_file".into()),
|
||||
("ZED_ROW".into(), "1".into()),
|
||||
("ZED_COLUMN".into(), "15".into()),
|
||||
("ZED_SELECTED_TEXT".into(), "is_i".into()),
|
||||
])
|
||||
}
|
||||
);
|
||||
|
@ -354,6 +359,7 @@ mod tests {
|
|||
("ZED_SYMBOL".into(), "this_is_a_test".into()),
|
||||
("ZED_ROW".into(), "1".into()),
|
||||
("ZED_COLUMN".into(), "1".into()),
|
||||
("ZED_SELECTED_TEXT".into(), "".into()),
|
||||
])
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue