Add page up/down bindings to the Markdown preview (#33403)
First time contributor here. 😊 I settled on markdown::MovePageUp and markdown::MovePageDown to match the names the editor uses for the same functionality. Closes #30246 Release Notes: - Support PgUp/PgDown in Markdown previews
This commit is contained in:
parent
123a25c58c
commit
f000dfebd2
5 changed files with 119 additions and 4 deletions
|
@ -8,7 +8,13 @@ pub mod markdown_renderer;
|
|||
|
||||
actions!(
|
||||
markdown,
|
||||
[OpenPreview, OpenPreviewToTheSide, OpenFollowingPreview]
|
||||
[
|
||||
MovePageUp,
|
||||
MovePageDown,
|
||||
OpenPreview,
|
||||
OpenPreviewToTheSide,
|
||||
OpenFollowingPreview
|
||||
]
|
||||
);
|
||||
|
||||
pub fn init(cx: &mut App) {
|
||||
|
|
|
@ -7,8 +7,8 @@ use editor::scroll::Autoscroll;
|
|||
use editor::{Editor, EditorEvent, SelectionEffects};
|
||||
use gpui::{
|
||||
App, ClickEvent, Context, Entity, EventEmitter, FocusHandle, Focusable, InteractiveElement,
|
||||
IntoElement, ListState, ParentElement, Render, RetainAllImageCache, Styled, Subscription, Task,
|
||||
WeakEntity, Window, list,
|
||||
IntoElement, IsZero, ListState, ParentElement, Render, RetainAllImageCache, Styled,
|
||||
Subscription, Task, WeakEntity, Window, list,
|
||||
};
|
||||
use language::LanguageRegistry;
|
||||
use settings::Settings;
|
||||
|
@ -19,7 +19,7 @@ use workspace::{Pane, Workspace};
|
|||
|
||||
use crate::markdown_elements::ParsedMarkdownElement;
|
||||
use crate::{
|
||||
OpenFollowingPreview, OpenPreview, OpenPreviewToTheSide,
|
||||
MovePageDown, MovePageUp, OpenFollowingPreview, OpenPreview, OpenPreviewToTheSide,
|
||||
markdown_elements::ParsedMarkdown,
|
||||
markdown_parser::parse_markdown,
|
||||
markdown_renderer::{RenderContext, render_markdown_block},
|
||||
|
@ -530,6 +530,26 @@ impl MarkdownPreviewView {
|
|||
) -> bool {
|
||||
!(current_block.is_list_item() && next_block.map(|b| b.is_list_item()).unwrap_or(false))
|
||||
}
|
||||
|
||||
fn scroll_page_up(&mut self, _: &MovePageUp, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
let viewport_height = self.list_state.viewport_bounds().size.height;
|
||||
if viewport_height.is_zero() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.list_state.scroll_by(-viewport_height);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn scroll_page_down(&mut self, _: &MovePageDown, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
let viewport_height = self.list_state.viewport_bounds().size.height;
|
||||
if viewport_height.is_zero() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.list_state.scroll_by(viewport_height);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
impl Focusable for MarkdownPreviewView {
|
||||
|
@ -580,6 +600,8 @@ impl Render for MarkdownPreviewView {
|
|||
.id("MarkdownPreview")
|
||||
.key_context("MarkdownPreview")
|
||||
.track_focus(&self.focus_handle(cx))
|
||||
.on_action(cx.listener(MarkdownPreviewView::scroll_page_up))
|
||||
.on_action(cx.listener(MarkdownPreviewView::scroll_page_down))
|
||||
.size_full()
|
||||
.bg(cx.theme().colors().editor_background)
|
||||
.p_4()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue