mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
fix(ffi): keep merged children in place and rename PageView to PageData
Merging a first child into its parent now gives its children the merged block's slot instead of appending them after the parent's other children. PageView clashed with Flutter's PageView widget in Dart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
305428eaea
commit
8c11d049fb
5 files changed
+104
-85
No files matched your search
@@ -55,7 +55,7 @@ impl BlockDto {
|
||||
|
||||
/// Everything the page view needs in one call.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PageView {
|
||||
pub struct PageData {
|
||||
pub page: PageDto,
|
||||
pub blocks: Vec<BlockDto>,
|
||||
pub aliases: Vec<String>,
|
||||
|
||||
@@ -42,7 +42,7 @@ impl SynapseGraph {
|
||||
|
||||
// ------------------------------------------------------------- pages
|
||||
|
||||
pub fn page(&self, id: String) -> Result<Option<PageView>> {
|
||||
pub fn page(&self, id: String) -> Result<Option<PageData>> {
|
||||
let g = self.lock();
|
||||
match g.get_page(parse_id(&id)?)? {
|
||||
Some(p) => Ok(Some(page_view(&g, &p)?)),
|
||||
@@ -51,7 +51,7 @@ impl SynapseGraph {
|
||||
}
|
||||
|
||||
/// Page by title or alias, without creating it.
|
||||
pub fn page_by_title(&self, title: String) -> Result<Option<PageView>> {
|
||||
pub fn page_by_title(&self, title: String) -> Result<Option<PageData>> {
|
||||
let g = self.lock();
|
||||
match g.page_by_title(&title)? {
|
||||
Some(p) => Ok(Some(page_view(&g, &p)?)),
|
||||
@@ -61,7 +61,7 @@ impl SynapseGraph {
|
||||
|
||||
/// Page by title or alias, created if missing (following a `[[link]]`). Date titles open
|
||||
/// the journal of that day.
|
||||
pub fn open_page(&self, title: String) -> Result<PageView> {
|
||||
pub fn open_page(&self, title: String) -> Result<PageData> {
|
||||
let g = self.lock();
|
||||
let page = match g.page_by_title(&title)? {
|
||||
Some(p) => p,
|
||||
@@ -115,7 +115,7 @@ impl SynapseGraph {
|
||||
// ---------------------------------------------------------- journals
|
||||
|
||||
/// The journal of `date` (created if missing).
|
||||
pub fn journal(&self, date: String) -> Result<PageView> {
|
||||
pub fn journal(&self, date: String) -> Result<PageData> {
|
||||
let g = self.lock();
|
||||
let p = g.journal(parse_date(&date)?)?;
|
||||
page_view(&g, &p)
|
||||
@@ -123,7 +123,7 @@ impl SynapseGraph {
|
||||
|
||||
/// Journals feed, newest first. With `before = None` it starts at today (creating today's
|
||||
/// journal); otherwise at the newest journal strictly before `before`.
|
||||
pub fn journals(&self, before: Option<String>, limit: u32) -> Result<Vec<PageView>> {
|
||||
pub fn journals(&self, before: Option<String>, limit: u32) -> Result<Vec<PageData>> {
|
||||
let g = self.lock();
|
||||
let mut out = Vec::new();
|
||||
let mut cursor = match before {
|
||||
@@ -293,7 +293,7 @@ fn asset_dto(a: synapse_core::Asset) -> AssetDto {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn page_view(g: &Graph, p: &Page) -> Result<PageView> {
|
||||
pub(crate) fn page_view(g: &Graph, p: &Page) -> Result<PageData> {
|
||||
let (prev, next) = match p.journal_date {
|
||||
Some(d) => {
|
||||
let n = g.journal_neighbors(d)?;
|
||||
@@ -301,7 +301,7 @@ pub(crate) fn page_view(g: &Graph, p: &Page) -> Result<PageView> {
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
Ok(PageView {
|
||||
Ok(PageData {
|
||||
page: PageDto::from(p),
|
||||
blocks: outline(g, p.id)?,
|
||||
aliases: g.aliases_of(p.id)?,
|
||||
|
||||
@@ -83,7 +83,8 @@ impl SynapseGraph {
|
||||
}
|
||||
|
||||
/// Backspace at the start of `id`: its text is appended to `into` (the previous visible
|
||||
/// block), its children are moved under `into`, and the block is deleted.
|
||||
/// block) and the block is deleted. Its children keep their visual place: they take the
|
||||
/// block's slot when `into` is its parent, otherwise they become last children of `into`.
|
||||
pub fn merge_block(&self, id: String, into: String) -> Result<Vec<BlockDto>> {
|
||||
let g = self.lock();
|
||||
let b = get(&g, parse_id(&id)?)?;
|
||||
@@ -100,11 +101,16 @@ impl SynapseGraph {
|
||||
.filter(|(_, c)| c.parent_id == Some(b.id))
|
||||
.map(|(_, c)| c.id)
|
||||
.collect();
|
||||
if !children.is_empty() && target.collapsed {
|
||||
if !children.is_empty() && target.collapsed && b.parent_id != Some(target.id) {
|
||||
g.set_collapsed(target.id, false)?;
|
||||
}
|
||||
let at = if b.parent_id == Some(target.id) {
|
||||
Placement::Before(b.id)
|
||||
} else {
|
||||
Placement::LastChildOf(Some(target.id))
|
||||
};
|
||||
for c in children {
|
||||
g.move_block(c, target.page_id, Placement::LastChildOf(Some(target.id)))?;
|
||||
g.move_block(c, target.page_id, at)?;
|
||||
}
|
||||
g.delete_block(b.id)?;
|
||||
outline(&g, target.page_id)
|
||||
|
||||
Reference in new issue
Block a user