Add an editor: diff clipboard with selection
action (#33283)
https://github.com/user-attachments/assets/d472fbdd-7736-4bd7-8a90-8cca356b2815 This PR adds `editor: diff clipboard with selection` - good for spotting the differences in eerily-similar code, which is when refactoring code, as you need to see what needs to be passed in in order to maintain previous behavior of both snippets. 1. Copy some text from anywhere 2. Highlight some text in Zed 3. Run `editor: diff clipboard with selection` Like JetBrains' IDEs and VS Code with the `PartialDiff` package, if the selection is empty, we take the entire buffer as the selection. Caveats: - We do not know the language of the text in the clipboard. I went ahead and just assumed that in most cases, it will be the same language as the selected text, which does mean we will highlight the old text incorrectly if they are copying from a different language, but I think in most cases, it will be the same, and the alternative of always having no syntax highlighting is worse. PyCharm seems to do the same thing. Release Notes: - Added an `editor: diff clipboard with selection` action --------- Co-authored-by: Junkui Zhang <364772080@qq.com> Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
parent
3e27fa1d92
commit
500ceaabcd
8 changed files with 671 additions and 56 deletions
|
@ -12,7 +12,7 @@ use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};
|
|||
use futures::channel::{mpsc, oneshot};
|
||||
use futures::future::join_all;
|
||||
use futures::{FutureExt, SinkExt, StreamExt};
|
||||
use git_ui::diff_view::DiffView;
|
||||
use git_ui::file_diff_view::FileDiffView;
|
||||
use gpui::{App, AsyncApp, Global, WindowHandle};
|
||||
use language::Point;
|
||||
use recent_projects::{SshSettings, open_ssh_project};
|
||||
|
@ -262,7 +262,7 @@ pub async fn open_paths_with_positions(
|
|||
let old_path = Path::new(&diff_pair[0]).canonicalize()?;
|
||||
let new_path = Path::new(&diff_pair[1]).canonicalize()?;
|
||||
if let Ok(diff_view) = workspace.update(cx, |workspace, window, cx| {
|
||||
DiffView::open(old_path, new_path, workspace, window, cx)
|
||||
FileDiffView::open(old_path, new_path, workspace, window, cx)
|
||||
}) {
|
||||
if let Some(diff_view) = diff_view.await.log_err() {
|
||||
items.push(Some(Ok(Box::new(diff_view))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue