Skip to content

Conversation

@MartinBourbier
Copy link
Contributor

This PR allows users to copy and paste timetables using simple standard shortcuts (ctrl+c, ctrl+v, ctrl+x).

Closes #13902

@MartinBourbier MartinBourbier self-assigned this Nov 10, 2025
@github-actions github-actions bot added the area:front Work on Standard OSRD Interface modules label Nov 10, 2025
@MartinBourbier MartinBourbier force-pushed the mbr/copy-paste-timetables branch from 7c7b708 to f4ebfc7 Compare November 10, 2025 10:01
if (!timetableItems) return;

const jsonString = timetableItemsToJson(selectedTimeTableIdsFromClick, timetableItems);
navigator.clipboard.writeText(jsonString);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use ClipboardItem + clipboard.write() instead of text, to indicate that a JSON blob is being copied? Could also set disposition as attachment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately from what I saw, the clipboard doesn't support writing JSON, it can only write plain text, html or png. :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, what do you mean? Does it throw an error? Does it silently do nothing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It throw an error (DOMException with not supported type to be more specific).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, ClipboardItem.supports('application/json') returns false… It seems like we'd need to use a custom web MIME type if we wanted to assign a different MIME type…


const ctrlV = useCallback(
async (event: KeyboardEvent) => {
if (!event.repeat && event.ctrlKey && event.key === 'v') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the paste event instead of catching a specific combination of keypresses?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


const ctrlC = useCallback(
(event: KeyboardEvent) => {
if (!event.repeat && event.ctrlKey && event.key === 'c') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use the copy event here instead too (together with event.preventDefault() to disable the built-in copy behavior).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@MartinBourbier MartinBourbier force-pushed the mbr/copy-paste-timetables branch from e1d1f08 to 1b945a3 Compare November 12, 2025 10:16
@MartinBourbier MartinBourbier force-pushed the mbr/copy-paste-timetables branch from 1b945a3 to 0cbf0ea Compare November 12, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:front Work on Standard OSRD Interface modules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Be able to import / export (copy / paste) train schedules and paced trains.

4 participants