mirror of
https://github.com/heyman/heynote.git
synced 2025-06-27 21:12:00 +02:00
Merge pull request #326 from heyman/feature-insert-current-datetime
Add functionality for inserting the current date and time
This commit is contained in:
commit
33e65a6127
@ -10,6 +10,7 @@ Here are the most notable changes in each release. For a more detailed list of c
|
|||||||
- Added a "command palette" that can be accessed by pressing `Ctrl/Cmd+Shift+P`, or just typing `>` in the buffer selector. The command palette allows you to discover all available commands in the app, and to quickly execute them.
|
- Added a "command palette" that can be accessed by pressing `Ctrl/Cmd+Shift+P`, or just typing `>` in the buffer selector. The command palette allows you to discover all available commands in the app, and to quickly execute them.
|
||||||
- Added support for configuring the tab size.
|
- Added support for configuring the tab size.
|
||||||
- Added functionality for moving blocks up and down. Default key bindings are `Ctrl/Cmd+Alt+Shift+Up` and `Ctrl/Cmd+Alt+Shift+Down`.
|
- Added functionality for moving blocks up and down. Default key bindings are `Ctrl/Cmd+Alt+Shift+Up` and `Ctrl/Cmd+Alt+Shift+Down`.
|
||||||
|
- Added functionality for inserting the current date and time. Default key binding is `Alt+Shift+D`.
|
||||||
|
|
||||||
### Other changes
|
### Other changes
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import { transposeChars } from "./block/transpose-chars.js"
|
|||||||
import { cutCommand, copyCommand, pasteCommand } from "./copy-paste.js"
|
import { cutCommand, copyCommand, pasteCommand } from "./copy-paste.js"
|
||||||
|
|
||||||
import { markModeMoveCommand, toggleSelectionMarkMode, selectionMarkModeCancel } from "./mark-mode.js"
|
import { markModeMoveCommand, toggleSelectionMarkMode, selectionMarkModeCancel } from "./mark-mode.js"
|
||||||
|
import { insertDateAndTime } from "./date-time.js"
|
||||||
|
|
||||||
|
|
||||||
const cursorPreviousBlock = markModeMoveCommand(gotoPreviousBlock, selectPreviousBlock)
|
const cursorPreviousBlock = markModeMoveCommand(gotoPreviousBlock, selectPreviousBlock)
|
||||||
@ -116,6 +117,7 @@ const HEYNOTE_COMMANDS = {
|
|||||||
selectPreviousBlock: cmdLessContext(selectPreviousBlock, "Selection", "Select to previous block"),
|
selectPreviousBlock: cmdLessContext(selectPreviousBlock, "Selection", "Select to previous block"),
|
||||||
selectNextBlock: cmdLessContext(selectNextBlock, "Selection", "Select to next block"),
|
selectNextBlock: cmdLessContext(selectNextBlock, "Selection", "Select to next block"),
|
||||||
nothing: cmdLessContext(nothing, "Misc", "Do nothing"),
|
nothing: cmdLessContext(nothing, "Misc", "Do nothing"),
|
||||||
|
insertDateAndTime: cmdLessContext(insertDateAndTime, "Misc", "Insert date and time"),
|
||||||
|
|
||||||
// directly from CodeMirror
|
// directly from CodeMirror
|
||||||
undo: cmdLessContext(undo, "Edit", "Undo"),
|
undo: cmdLessContext(undo, "Edit", "Undo"),
|
||||||
|
20
src/editor/date-time.js
Normal file
20
src/editor/date-time.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
export const insertDateAndTime = ({ state, dispatch }) => {
|
||||||
|
if (state.readOnly) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateText = new Date().toLocaleString(undefined, {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
})
|
||||||
|
dispatch(state.replaceSelection(dateText),
|
||||||
|
{
|
||||||
|
scrollIntoView: true,
|
||||||
|
userEvent: "input",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return true;
|
||||||
|
}
|
@ -42,6 +42,7 @@ export const DEFAULT_KEYMAP = [
|
|||||||
...cmdShift("End", "cursorLineBoundaryForward", "selectLineBoundaryForward"),
|
...cmdShift("End", "cursorLineBoundaryForward", "selectLineBoundaryForward"),
|
||||||
cmd("Alt-Mod-Shift-ArrowUp", "moveCurrentBlockUp"),
|
cmd("Alt-Mod-Shift-ArrowUp", "moveCurrentBlockUp"),
|
||||||
cmd("Alt-Mod-Shift-ArrowDown", "moveCurrentBlockDown"),
|
cmd("Alt-Mod-Shift-ArrowDown", "moveCurrentBlockDown"),
|
||||||
|
cmd("Alt-Shift-d", "insertDateAndTime"),
|
||||||
cmd("Backspace", "deleteCharBackward"),
|
cmd("Backspace", "deleteCharBackward"),
|
||||||
cmd("Delete", "deleteCharForward"),
|
cmd("Delete", "deleteCharForward"),
|
||||||
cmd("Escape", "simplifySelection"),
|
cmd("Escape", "simplifySelection"),
|
||||||
|
@ -37,3 +37,12 @@ test("first block is protected", async ({ page }) => {
|
|||||||
expect(await heynotePage.getBlockContent(0)).toBe("")
|
expect(await heynotePage.getBlockContent(0)).toBe("")
|
||||||
expect(await heynotePage.getContent()).toBe(initialContent)
|
expect(await heynotePage.getContent()).toBe(initialContent)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("insert current date and time", async ({ page }) => {
|
||||||
|
const expectedYear = new Date().toLocaleString(undefined, {
|
||||||
|
year: 'numeric',
|
||||||
|
})
|
||||||
|
await page.locator("body").press("Alt+Shift+D")
|
||||||
|
expect(await heynotePage.getBlockContent(0)).toContain(expectedYear)
|
||||||
|
expect((await heynotePage.getBlockContent(0)).length).toBeGreaterThan(0)
|
||||||
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user