Add draggable table column resizing - #451
Conversation
|
Thanks for this — a lot of careful work, and the non-persistence parts are well done: the token-gated My main concern with this PR is the persistence model, not the feature. The path-keyed How would you feel about persisting column widths in the document itself, using the table's delimiter row? A pipe table's delimiter dashes are ignored by the renderer (only colons matter), so we could co-opt dash count as a proportional width: → apply I confirmed our renderer cooperates: against our pinned hoedown 3.0.7, dash count above the minimum has zero effect on output ( You'd keep essentially all the front end — handles, CSS, bridge, colgroup logic; only the persistence half changes. Happy to take that piece on myself if you'd rather not redo it. (Separately: the baseline #432 regression is handled in #440, so this PR can focus purely on resizing.) Generated by Claude Code |
|
Putting the formatting in the document would make it incompatible with prior versions of macdown and just about every other markdown editor out there. A local store of this data in a user folder could suffice, or if they didn't want that, to just resize as needed each time it's opened. The former would be preferred though. |
I like the idea behind this feature and I agree that it should be persistent. I didn't realize just what a pain it was to have the fixed column widths. What do you mean when you say "incompatible with prior versions of macdown and just about every other markdown editor out there"? Aside from doing a quick spike in Hoedown to make sure that the idea would work, I only did a cursory search but I am unaware of any Markdown parsers that care how many dashes are present in that row. If I'm missing something, please let me know! Even beyond my vague concerns about long term maintenance burden, I'd love it if we could find a solution that doesn't break if a user copies the file to a different computer, or potentially, a different folder on the same computer. |
|
Yeah, it's a good idea. I'm not sure if I should build in the things like alignment/justification as the Github Flavored Markdown spec allows. I'd personally say 'yes', with an option in the Settings dialog to allow/disallow it, but that might turn into biting off a lot more than would be appropriate. |
|
@aseelye I'm happy to take over where you've left off -- I certainly don't want to hand you a bunch of extra work you didn't originally sign up for, just because I had a different idea of where this ought to slot in architecturally. You've gotten the ball rolling, and I'm happy to get this extremely valuable feature to a place where I'd be glad to merge it. Please let me know whether you'd prefer that or to finish it yourself? |
|
To the contrary, please do. I'm sure whatever you patch it would fit more cleanly. FWIW I did like the idea of jclark's to insert the additional hyphens instead of a local datastore of file settings, will be more portable and better for group collabs. Also might want to consider using the github markdown extensions down the road for increased formatting options. |
|
Taking this over per the discussion above — proceeding with the in-document, delimiter-row persistence model. Thanks again @aseelye. I'm keeping your front end essentially intact (the drag handles, Persistence model. Column widths live in the document, encoded as the dash counts of the pipe-table delimiter row ( Behavior / constraints:
Explicitly out of scope (candidate future issue): the GFM alignment/justification toggle — @aseelye raised it and flagged it as possible scope creep; agreed, deferring. The #432 natural-width regression is handled separately in #440, not here. Open items I'll carry into the PR: the exact source-rewrite mechanism (the checkbox-toggle path I named does a whole-document text swap; a targeted, undoable edit may be preferable for selection/undo safety — I'll decide against the actual code), and correct-table targeting when a document holds multiple tables (index/hash mapping between the DOM and the source). Tests that asserted the sidecar behavior are removed or retargeted; the bridge, token-gate, CSS, and export tests are kept. @aseelye's original commit is preserved with authorship intact. |
) Draggable table column resizing in the live preview, reworked from @aseelye's PR #451 contribution to hold width state in memory only, with no document mutation or persistence of any kind. ## Behavior - Drag a column-boundary handle in a rendered table to resize it live in the preview. - Double-click a handle to reset that column to natural sizing. - Widths survive incremental preview updates (typing) because the preview's JS context persists across DOM replacement. - Widths reset on a full preview reload (style change, window reopen) and on document close. Nothing is written to the document or to disk. - Export (HTML/PDF) is unaffected by resize state. ## What changed from @aseelye's original PR #451 His interactive front end (drag handles, table identity via header-hash + index, minimum column width) is unchanged. Removed entirely: the native persistence layer — bridge token, `x-macdown-table-layout://` custom URL scheme, `table-layouts.json` sidecar file, and the associated load/save/reset logic in `MPDocument.m`/`MPRenderer.m`/`.h`. `table-resize.js` now holds width state in a closure-scoped map instead of round-tripping through the native bridge. His authorship is preserved via a straight cherry-pick (`a5f9b40`) as the base commit, with the persistence removal as a separate commit on top. ## Judgment calls - **No Markdown parsing, no export of resized widths.** The feature is purely DOM-level and is unaffected by the hoedown → cmark-gfm parser swap (#515 / v3000.1). - **Table identity is header-hash + index**, unchanged from the original PR. Renaming a header or reordering tables (which shifts the index) loses that table's widths for the session — accepted as an ephemeral-view-state tradeoff. - **`export.css`'s bundled `th { white-space: nowrap }` change rides along unchanged** from the original PR. It affects all table rendering, including export, not just the live-resize feature — a UX change serving the same table-readability goal, kept as part of this PR rather than split out. - **In-document persistence remains a future feature**, tracked separately against a dash-count design built for cmark-gfm rather than the sidecar-file approach removed here. ## Testing `CI=true xcodebuild test -workspace "MacDown 3000.xcworkspace" -scheme "MacDown (MacDown 3000 project)" -destination 'platform=macOS'`: 1225 tests, 76 expected failures, 0 unexpected. Headless tests cover: the renderer emits no layout JSON or table-layout bridge token; `table-resize.js` is registered in the preview scripts; export HTML/CSS behavior is unaffected; the removed URL-scheme handler leaves no trace. Drag interaction and width re-application after DOM replacement run only in a live WebView and are manual-QA items. Related to #451 --------- Co-authored-by: Aaron <aaron@mdo.net>

Adds draggable column resizing for Markdown tables in the live preview, with widths persisted outside the Markdown file in Application Support. Includes renderer and persistence tests.