Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/winc-app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ enum Drag {
Hex,
/// 在 Markdown 预览中拖选文字(`App::drag_markdown`)。
MarkdownText,
/// 在 Properties 预览中拖选解码后的文字。
PropertiesText,
/// 拖动预览中图片的把手调整大小(`App::drag_image_resize`)。
ImageResize,
/// 在表格中拖选单元格(`App::drag_table`)。
Expand Down
22 changes: 21 additions & 1 deletion crates/winc-app/src/app/editor/editing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,23 @@ impl App {

/// 复制选区(`cut` 为 `true` 时剪切);没有选区时操作光标所在的整行。
pub(in crate::app) fn copy(&mut self, cut: bool) {
if self.properties_focused() {
// 与其他只读文字预览相同,剪切只复制,不修改源文档。
if self.properties_has_selection() {
if let Some(text) = self.properties_selected_text() {
if !text.is_empty() {
self.set_clipboard(text, false);
self.flash(t!("editor-selection-copied"));
}
} else {
self.flash(t!(
"editor-selection-too-large-to-copy",
size = COPY_LIMIT >> 20
));
}
}
return;
}
// 十六进制视图:复制选中的字节,写成十六进制;只读,不能剪切。
if self.hex_active() {
if !cut {
Expand Down Expand Up @@ -611,7 +628,7 @@ impl App {
self.edit_field(|field| field.insert(&content));
}
}
Focus::Editor => self.paste_into_editor(),
Focus::Editor if !self.properties_focused() => self.paste_into_editor(),
Focus::Tree => self.paste_into_tree(),
Focus::Terminal => self.terminal_paste(),
_ => {}
Expand Down Expand Up @@ -645,6 +662,9 @@ impl App {
///
/// 文档不可编辑时在状态栏提示原因,不执行命令。
pub(in crate::app) fn run(&mut self, command: Command) {
if self.properties_focused() {
return;
}
let page = self.page_lines();
let tab_width = self.editor.active_tab_width();
let lines_before = self.line_count();
Expand Down
15 changes: 13 additions & 2 deletions crates/winc-app/src/app/editor/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ pub(crate) enum ScrollArea {
Table,
/// 表格预览的水平滚动条。
TableHorizontal,
/// Properties 预览的竖直滚动条。
Properties,
/// Properties 预览的水平滚动条。
PropertiesHorizontal,
/// 链接地址和写作命令的补全列表。
Suggest,
}

impl ScrollArea {
/// 全部区域,遍历时用。
const ALL: [ScrollArea; 20] = [
const ALL: [ScrollArea; 22] = [
ScrollArea::Editor,
ScrollArea::EditorHorizontal,
ScrollArea::DiffLeftHorizontal,
Expand All @@ -87,6 +91,8 @@ impl ScrollArea {
ScrollArea::MarkdownToc,
ScrollArea::Table,
ScrollArea::TableHorizontal,
ScrollArea::Properties,
ScrollArea::PropertiesHorizontal,
ScrollArea::Suggest,
];

Expand All @@ -112,6 +118,8 @@ impl ScrollArea {
ScrollArea::MarkdownToc => Some(Scrollbar::MarkdownToc),
ScrollArea::Table => Some(Scrollbar::Table),
ScrollArea::TableHorizontal => Some(Scrollbar::TableHorizontal),
ScrollArea::Properties => Some(Scrollbar::Properties),
ScrollArea::PropertiesHorizontal => Some(Scrollbar::PropertiesHorizontal),
ScrollArea::Suggest => None,
}
}
Expand All @@ -125,6 +133,7 @@ impl ScrollArea {
| ScrollArea::TreeHorizontal
| ScrollArea::MarkdownTable
| ScrollArea::TableHorizontal
| ScrollArea::PropertiesHorizontal
)
}
}
Expand Down Expand Up @@ -169,7 +178,7 @@ struct Reveal {
}

/// 编辑区窗格里的滚动条:拆分后每个窗格各有一份显示状态。
pub(crate) const PANE_AREAS: [ScrollArea; 11] = [
pub(crate) const PANE_AREAS: [ScrollArea; 13] = [
ScrollArea::Editor,
ScrollArea::EditorHorizontal,
ScrollArea::DiffLeftHorizontal,
Expand All @@ -181,6 +190,8 @@ pub(crate) const PANE_AREAS: [ScrollArea; 11] = [
ScrollArea::MarkdownToc,
ScrollArea::Table,
ScrollArea::TableHorizontal,
ScrollArea::Properties,
ScrollArea::PropertiesHorizontal,
];

/// 各区域滚动条的显示状态,以及鼠标所在的滚动条。
Expand Down
30 changes: 23 additions & 7 deletions crates/winc-app/src/app/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use winc_preview::markdown::paragraph::Kind;

use super::*;
use crate::field::TextField;
use crate::keymap::{Action, Context};
use crate::keymap::{Action, Context, Group};
use crate::layout::{PanelButton, SearchButton, SettingsPage, SidebarView};

impl App {
Expand All @@ -23,7 +23,7 @@ impl App {
if !self.action_available(action) {
return false;
}
if action == Copy && self.vim_side_copy() {
if action == Copy && !self.properties_focused() && self.vim_side_copy() {
return true;
}
if let Some(done) = self.diff_edit_action(action) {
Expand Down Expand Up @@ -70,11 +70,12 @@ impl App {
}

// Vim 的普通与可视模式下,撤销、重做、复制、剪切、粘贴由 Vim 层按对应的命令执行。
let vim_keys = if self.vim.is_some() && self.focus == Focus::Editor {
self.vim_equivalent(action)
} else {
None
};
let vim_keys =
if self.vim.is_some() && self.focus == Focus::Editor && !self.properties_focused() {
self.vim_equivalent(action)
} else {
None
};

match action {
ShowCommands => self.toggle_palette(),
Expand Down Expand Up @@ -207,6 +208,7 @@ impl App {
Copy => self.copy(false),
Paste => self.paste(),
SelectAll if self.markdown_focused() => self.markdown_select_all(),
SelectAll if self.properties_focused() => self.properties_select_all(),
SelectAll if self.table_focused() => self.table_select_all(),
SelectAll if self.focus == Focus::Tree => {
if let Some(ws) = &mut self.editor.workspace {
Expand Down Expand Up @@ -544,6 +546,20 @@ impl App {

/// 命令当前是否可用:属于某个模块的命令只在模块开着时可用。
pub(in crate::app) fn action_available(&self, action: Action) -> bool {
if self.properties_focused()
&& !matches!(action, Action::Copy | Action::Cut | Action::SelectAll)
&& (action.group() == Group::Edit
|| matches!(
action,
Action::FindNext
| Action::FindPrevious
| Action::ReplaceOne
| Action::ReplaceAll
| Action::GitRevertChange
))
{
return false;
}
match action {
Action::RunConfiguration if self.editor.root().is_none() => return false,
// 编辑提交说明只在日志里可用;其余位置同一个键执行其他命令。
Expand Down
2 changes: 2 additions & 0 deletions crates/winc-app/src/app/input/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ pub enum MenuTarget {
Editor(DocumentId),
/// Markdown 预览(分栏右边,或只看预览时整个编辑区)。
Markdown,
/// Properties 预览中的解码文字。
Properties(DocumentId),
/// 差异标签里的文字:`true` 是右侧(工作区,可以编辑),`false` 是左侧。
Diff(DocumentId, bool),
/// 差异标签中两侧的行号栏、逐行追溯一栏。
Expand Down
8 changes: 8 additions & 0 deletions crates/winc-app/src/app/input/context_menu/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ impl App {
MenuTarget::Terminal(block)
} else if self.markdown_context_target(x, y) {
MenuTarget::Markdown
} else if let Some(id) = self.properties_context_target(x, y) {
MenuTarget::Properties(id)
} else if let Some(id) = self.editor_context_target(x, y) {
MenuTarget::Editor(id)
} else {
Expand Down Expand Up @@ -301,6 +303,7 @@ impl App {
}
let id = doc.id;

self.unfocus_properties();
self.focus = Focus::Editor;
self.ime.preedit.clear();
Some(id)
Expand Down Expand Up @@ -517,6 +520,10 @@ impl App {
]);
menu
}
MenuTarget::Properties(_) => vec![
MenuEntry::Item(MenuCommand::Copy, self.properties_has_selection()),
MenuEntry::Item(MenuCommand::SelectAll, true),
],
MenuTarget::Markdown => {
let mut menu = vec![
MenuEntry::Item(MenuCommand::Copy, self.markdown_selected_text().is_some()),
Expand Down Expand Up @@ -802,6 +809,7 @@ impl App {
| MenuTarget::Diff(..)
| MenuTarget::DiffGutter(..)
| MenuTarget::Markdown
| MenuTarget::Properties(_)
| MenuTarget::LogCommit(_) => Context::Editor,
MenuTarget::Terminal(_) | MenuTarget::TerminalTab(_) => Context::Terminal,
MenuTarget::SearchResult(..) => Context::Panel,
Expand Down
8 changes: 8 additions & 0 deletions crates/winc-app/src/app/input/context_menu/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ impl App {
}
}
MenuTarget::Editor(id) => self.run_editor_command(command, id),
MenuTarget::Properties(id) => {
if self.editor.active().map(|doc| doc.id) == Some(id)
&& self.properties_focused()
&& let Some(action) = command.action()
{
self.run_action(action);
}
}
MenuTarget::Markdown => match command {
MenuCommand::Cut => self.copy(true),
MenuCommand::Copy => self.copy(false),
Expand Down
13 changes: 13 additions & 0 deletions crates/winc-app/src/app/input/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl App {
// 的按键继续按原有的顺序处理。
// 两步组合键的第二步仍由键位表处理;Vim 没有带 `Alt` 的命令,应用绑定的 `Alt` 组合归应用。
if self.vim.is_some()
&& !self.properties_focused()
&& self.pending_chord.is_none()
&& !self.alt_shortcut(event, &base)
&& (self.vim_key_event(event) || self.vim_list_key(&event.logical_key, &base))
Expand Down Expand Up @@ -294,6 +295,17 @@ impl App {
}
return;
}
if self.properties_focused() {
if event.logical_key == Key::Named(NamedKey::Escape) {
if self.bars.find.open {
self.close_search();
}
self.unfocus_properties();
} else {
self.properties_key(&event.logical_key, cmd);
}
return;
}
if self.log_active() {
self.log_key(&event.logical_key);
return;
Expand Down Expand Up @@ -1144,6 +1156,7 @@ impl App {
pub(in crate::app) fn takes_text(&self) -> bool {
match self.focus {
Focus::Terminal => self.terminal.tab().is_some_and(|t| t.ended.is_none()),
Focus::Editor if self.properties_focused() => false,
Focus::Editor
if self
.vim_mode()
Expand Down
15 changes: 14 additions & 1 deletion crates/winc-app/src/app/input/mouse/click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ impl App {
self.preview.markdown.focused = false;
self.preview.markdown.selection = None;
}
if !matches!(
target,
Target::Properties
| Target::Scrollbar(Scrollbar::Properties | Scrollbar::PropertiesHorizontal, _)
) {
self.unfocus_properties();
}

// 点击的目标由 `target_at` 决定(与悬停同一个顺序);只有点击才有的规则写成前面的
// 分支:快速打开面板开着时点其他位置关掉快速打开面板,正在输入名字时点其他位置
Expand Down Expand Up @@ -235,6 +242,7 @@ impl App {
Target::MarkdownLink(link) => self.open_markdown_link(link),
Target::MarkdownToc(target) => self.press_toc(target),
Target::MarkdownText(_) => self.click_markdown(x, y),
Target::Properties => self.click_properties(x, y),
Target::ImageHandle => {
if let Some(image) = self.image_handle_at(x, y) {
self.start_image_resize(image, x);
Expand All @@ -259,7 +267,12 @@ impl App {
}
}
Target::RulerChange(hunk) => self.go_to_change(hunk),
Target::Scrollbar(bar, grab) => self.grab_scrollbar(bar, grab),
Target::Scrollbar(bar, grab) => {
if matches!(bar, Scrollbar::Properties | Scrollbar::PropertiesHorizontal) {
self.focus_properties();
}
self.grab_scrollbar(bar, grab);
}
Target::Minimap => self.press_minimap(y),
Target::Crumb(index) => self.open_crumb_menu(index),
Target::Status(item) => self.open_status_menu(item),
Expand Down
7 changes: 7 additions & 0 deletions crates/winc-app/src/app/input/mouse/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ impl App {
bar: bar @ (Scrollbar::Table | Scrollbar::TableHorizontal),
grab,
} => self.drag_table_scrollbar(bar == Scrollbar::TableHorizontal, (x, y), grab),
Drag::Scrollbar {
bar: bar @ (Scrollbar::Properties | Scrollbar::PropertiesHorizontal),
grab,
} => {
self.drag_properties_scrollbar(bar == Scrollbar::PropertiesHorizontal, (x, y), grab)
}
Drag::Scrollbar {
bar: Scrollbar::PdfStrip,
grab,
Expand Down Expand Up @@ -423,6 +429,7 @@ impl App {
Drag::LogText => self.drag_log_text(x, y),
Drag::Hex => self.drag_hex(x, y),
Drag::MarkdownText => self.drag_markdown(x, y),
Drag::PropertiesText => self.drag_properties(x, y),
Drag::ImageResize => self.drag_image_resize(x),
Drag::TableCells => self.drag_table(x, y),
Drag::Field => {
Expand Down
31 changes: 29 additions & 2 deletions crates/winc-app/src/app/input/mouse/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ impl App {
Target::MarkdownToc(target) => Hover::MarkdownToc(target),
Target::MarkdownText(Some(link)) => Hover::MarkdownLinkText(link),
Target::ImageHandle => Hover::ImageHandle,
Target::MarkdownText(None) | Target::PdfThumb(_) | Target::Picture => Hover::None,
Target::MarkdownText(None)
| Target::PdfThumb(_)
| Target::Picture
| Target::Properties => Hover::None,
Target::PdfTool(tool) => Hover::PdfTool(tool),
Target::LatexStatus => Hover::LatexStatus,
Target::LatexProblem(line) => Hover::LatexProblem(line),
Expand Down Expand Up @@ -466,6 +469,9 @@ impl App {
None => Target::Terminal,
};
}
if self.properties_area_at(x, y) {
return Target::Properties;
}
if l.tree.contains(x, y) || self.in_tree_overflow(x, y) {
return Target::Tree(self.tree_row_at(y));
}
Expand Down Expand Up @@ -646,6 +652,21 @@ impl App {
}

// 预览(分栏时位于右侧,仅预览时占满编辑区)先于编辑区判断,仅预览时两者重叠。
if self.properties_area_at(x, y) {
let (track, scroll, content) = self.properties_vscrollbar()?;
if x >= track.right() - SCROLLBAR_HIT
&& let Some(thumb) = scrollbar_thumb(track, scroll, content)
{
return Some((Scrollbar::Properties, grab(y, thumb.y, thumb.h)));
}
let (track, scroll, content) = self.properties_hscrollbar()?;
if track.contains(x, y) && y >= track.bottom() - SCROLLBAR_HIT {
let thumb = hscrollbar_thumb(track, scroll, content)?;
return Some((Scrollbar::PropertiesHorizontal, grab(x, thumb.x, thumb.w)));
}
return None;
}

let preview = self.preview.markdown.area;
// 标题列表覆盖在预览之上,先于预览判断;图钉按钮所在的位置不属于滚动条。
let list = &self.preview.markdown.toc_list;
Expand Down Expand Up @@ -871,7 +892,11 @@ impl App {
|| self.over_diff_text(x, y) && x < self.layout.editor.right() - SCROLLBAR_HIT;
// 日志详情中可选择的文字上(不含可点击的提交号和文件)显示文本光标。
let in_field = self.field_at(x, y).is_some()
|| matches!(self.pointer.drag, Drag::LogText | Drag::MarkdownText)
|| matches!(
self.pointer.drag,
Drag::LogText | Drag::MarkdownText | Drag::PropertiesText
)
|| self.properties_area_at(x, y)
|| (self.preview.markdown.area.contains(x, y) && self.markdown_link_at(x, y).is_none())
|| (self.log_active()
&& crate::layout::hit(&self.hits.log, x, y).is_none()
Expand Down Expand Up @@ -1018,6 +1043,8 @@ pub(super) enum Target {
/// Markdown 预览中可以选择文字的区域;参数为鼠标下的链接(可编辑的预览中单击链接放置
/// 光标,不打开它)。
MarkdownText(Option<usize>),
/// Properties 预览的文字区域。
Properties,
/// 可编辑的预览中图片的把手。
ImageHandle,
/// 标签,参数为标签下标与是否位于关闭按钮上。
Expand Down
Loading