-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created and updated times #56
base: main
Are you sure you want to change the base?
Changes from all commits
02ebd20
9960680
4b23af2
a348d6e
e842a10
fc5afe7
d2e31e8
8918c30
399a189
a5c8d53
1497cfe
44e764b
761ca5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
"themeSetting", | ||
"autoUpdate", | ||
"allowBetaVersions", | ||
"createdTime", | ||
"updatedTime", | ||
], | ||
|
||
components: { | ||
|
@@ -68,6 +70,11 @@ | |
Sel <span class="num">{{ selectionSize }}</span> | ||
</template> | ||
</div> | ||
<div class="status-block updated-time" v-if="updatedTime !== ''"> | ||
Updated <span class="time">{{ updatedTime }}</span> | ||
<!-- Show the created time as well -- too verbose --> | ||
<!-- <span v-if="createdTime !== updatedTime"> (Created {{ createdTime }})</span> --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looked too busy to me. Perhaps the better UI would be to click on the udpated time to see the created time? That wouldn't be clear either though. Feel free to adjust this as you see it |
||
</div> | ||
<div class="spacer"></div> | ||
<div | ||
@click="$emit('openLanguageSelector')" | ||
|
@@ -140,6 +147,14 @@ | |
color: rgba(255, 255, 255, 0.55) | ||
.num | ||
color: rgba(255, 255, 255, 0.75) | ||
.updated-time | ||
color: rgba(255, 255, 255, 0.7) | ||
.time | ||
color: rgba(255, 255, 255, 1.0) | ||
+dark-mode | ||
color: rgba(255, 255, 255, 0.55) | ||
.time | ||
color: rgba(255, 255, 255, 0.75) | ||
.lang .auto | ||
color: rgba(255, 255, 255, 0.7) | ||
+dark-mode | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,10 @@ import { heynoteEvent, LANGUAGE_CHANGE } from "../annotation.js"; | |
import { SelectionChangeEvent } from "../event.js" | ||
import { mathBlock } from "./math.js" | ||
import { emptyBlockSelected } from "./select-all.js"; | ||
import { newUpdatedTime, displayTime, timeMatcher } from "../time.js"; | ||
import { LANGUAGES } from '../languages.js'; | ||
|
||
const languageTokensMatcher = LANGUAGES.map(l => l.token).join("|") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to copy this snippet over a few times - perhaps this goes in |
||
|
||
// tracks the size of the first delimiter | ||
let firstBlockDelimiterSize | ||
|
@@ -25,12 +28,19 @@ function getBlocks(state, timeout=50) { | |
const langNode = type.node.getChild("NoteLanguage") | ||
const language = state.doc.sliceString(langNode.from, langNode.to) | ||
const isAuto = !!type.node.getChild("Auto") | ||
const createdAtNode = type.node.getChild("NoteCreated") | ||
const updatedAtNode = type.node.getChild("NoteUpdated") | ||
const contentNode = type.node.nextSibling | ||
|
||
blocks.push({ | ||
language: { | ||
name: language, | ||
auto: isAuto, | ||
}, | ||
time: { | ||
created: createdAtNode ? state.doc.sliceString(createdAtNode.from, createdAtNode.to) : null, | ||
updated: updatedAtNode ? state.doc.sliceString(updatedAtNode.from, updatedAtNode.to) : null, | ||
}, | ||
content: { | ||
from: contentNode.from, | ||
to: contentNode.to, | ||
|
@@ -326,13 +336,44 @@ const emitCursorChange = (editor) => ViewPlugin.fromClass( | |
selectionSize, | ||
language: block.language.name, | ||
languageAuto: block.language.auto, | ||
createdTime: displayTime(block.time.created), | ||
updatedTime: displayTime(block.time.updated), | ||
})) | ||
} | ||
} | ||
} | ||
} | ||
) | ||
|
||
const updateTimeOnChange = EditorState.transactionFilter.of((tr) => { | ||
if (!tr.docChanged) return tr | ||
|
||
const state = tr.startState | ||
const block = getActiveNoteBlock(state) | ||
|
||
// Block updates to time when deleting the last content in a block | ||
if ((block.content.from === block.content.to) && !tr.changes.inserted.length) return tr | ||
|
||
// this adds a slight debounce so the delimiter is only updated every second | ||
const updatedTime = newUpdatedTime() | ||
if (block.time.updated === updatedTime) return tr | ||
|
||
const language = block.language.name | ||
const auto = block.language.auto | ||
const createdTimeStr = block.time.created || "" | ||
const updatedTimeStr = block.time.updated ? updatedTime : "" | ||
|
||
// return original transaction, with additional transaction to update time in delimiter | ||
return [tr, { | ||
changes: { | ||
from: block.delimiter.from, | ||
to: block.delimiter.to, | ||
insert: `\n∞∞∞${language}${auto ? '-a' : ''}${createdTimeStr}${updatedTimeStr}\n`, | ||
}, | ||
filter: false | ||
}] | ||
}) | ||
|
||
export const noteBlockExtension = (editor) => { | ||
return [ | ||
blockState, | ||
|
@@ -344,5 +385,8 @@ export const noteBlockExtension = (editor) => { | |
emitCursorChange(editor), | ||
mathBlock, | ||
emptyBlockSelected, | ||
updateTimeOnChange, | ||
] | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { EditorSelection } from "@codemirror/state" | ||
import { LANGUAGES } from '../languages.js'; | ||
import { heynoteEvent, LANGUAGE_CHANGE, CURRENCIES_LOADED } from "../annotation.js"; | ||
import { blockState, getActiveNoteBlock, getNoteBlockFromPos } from "./block" | ||
import { blockState, getActiveNoteBlock, getNoteBlockFromPos} from "./block" | ||
import { moveLineDown, moveLineUp } from "./move-lines.js"; | ||
import { selectAll } from "./select-all.js"; | ||
import { newCreatedUpdatedTime, newUpdatedTime, timeMatcher } from "../time.js"; | ||
|
||
export { moveLineDown, moveLineUp, selectAll } | ||
const languageTokensMatcher = LANGUAGES.map(l => l.token).join("|") | ||
|
||
export { moveLineDown, moveLineUp, selectAll } | ||
|
||
export const insertNewBlockAtCursor = ({ state, dispatch }) => { | ||
if (state.readOnly) | ||
|
@@ -14,9 +17,9 @@ export const insertNewBlockAtCursor = ({ state, dispatch }) => { | |
const currentBlock = getActiveNoteBlock(state) | ||
let delimText; | ||
if (currentBlock) { | ||
delimText = `\n∞∞∞${currentBlock.language.name}${currentBlock.language.auto ? "-a" : ""}\n` | ||
delimText = `\n∞∞∞${currentBlock.language.name}${currentBlock.language.auto ? "-a" : ""}${newCreatedUpdatedTime()}\n` | ||
} else { | ||
delimText = "\n∞∞∞text-a\n" | ||
delimText = `\n∞∞∞text-a${newCreatedUpdatedTime()}\n` | ||
} | ||
dispatch(state.replaceSelection(delimText), | ||
{ | ||
|
@@ -32,7 +35,7 @@ export const addNewBlockAfterCurrent = ({ state, dispatch }) => { | |
if (state.readOnly) | ||
return false | ||
const block = getActiveNoteBlock(state) | ||
const delimText = "\n∞∞∞text-a\n" | ||
const delimText = `\n∞∞∞text-a${newCreatedUpdatedTime()}\n` | ||
|
||
dispatch(state.update({ | ||
changes: { | ||
|
@@ -50,14 +53,16 @@ export const addNewBlockAfterCurrent = ({ state, dispatch }) => { | |
export function changeLanguageTo(state, dispatch, block, language, auto) { | ||
if (state.readOnly) | ||
return false | ||
const delimRegex = /^\n∞∞∞[a-z]{0,16}(-a)?\n/g | ||
const delimRegex = new RegExp(`\\n∞∞∞(${languageTokensMatcher})(-a)?(-c${timeMatcher})?(-u${timeMatcher})?\\n`, "g") | ||
if (state.doc.sliceString(block.delimiter.from, block.delimiter.to).match(delimRegex)) { | ||
//console.log("changing language to", language) | ||
const createdTimeStr = block.time.created || "" | ||
const updatedTimeStr = block.time.updated ? newUpdatedTime() : "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't explicitly needed - this will get updated by the |
||
// console.log("changing language to", language) | ||
dispatch(state.update({ | ||
changes: { | ||
from: block.delimiter.from, | ||
to: block.delimiter.to, | ||
insert: `\n∞∞∞${language}${auto ? '-a' : ''}\n`, | ||
insert: `\n∞∞∞${language}${auto ? '-a' : ''}${createdTimeStr}${updatedTimeStr}\n`, | ||
}, | ||
annotations: [heynoteEvent.of(LANGUAGE_CHANGE)], | ||
})) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
export class SelectionChangeEvent extends Event { | ||
constructor({cursorLine, language, languageAuto, selectionSize}) { | ||
constructor({cursorLine, language, languageAuto, selectionSize, createdTime, updatedTime}) { | ||
super("selectionChange") | ||
this.cursorLine = cursorLine | ||
this.selectionSize = selectionSize | ||
this.language = language | ||
this.languageAuto = languageAuto | ||
this.createdTime = createdTime | ||
this.updatedTime = updatedTime | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import { ExternalTokenizer } from '@lezer/lr' | ||
import { NoteContent } from "./parser.terms.js" | ||
import { LANGUAGES } from '../languages.js'; | ||
import { timeMatcher } from '../time.js'; | ||
|
||
const EOF = -1; | ||
|
||
const FIRST_TOKEN_CHAR = "\n".charCodeAt(0) | ||
const SECOND_TOKEN_CHAR = "∞".charCodeAt(0) | ||
|
||
const languageTokensMatcher = LANGUAGES.map(l => l.token).join("|") | ||
const tokenRegEx = new RegExp(`^\\n∞∞∞(${languageTokensMatcher})(-a)?\\n`, "g") | ||
const tokenRegEx = new RegExp(`^\\n∞∞∞(${languageTokensMatcher})(-a)?(-c${timeMatcher})?(-u${timeMatcher})?\\n`, "g") | ||
|
||
export const noteContent = new ExternalTokenizer((input) => { | ||
let current = input.peek(0); | ||
|
@@ -23,7 +24,7 @@ export const noteContent = new ExternalTokenizer((input) => { | |
// so we don't need to check for the rest of the token | ||
if (current === FIRST_TOKEN_CHAR && next === SECOND_TOKEN_CHAR) { | ||
let potentialLang = ""; | ||
for (let i=0; i<18; i++) { | ||
for (let i=0; i<62; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note I added the 40 characters of the times to this. |
||
potentialLang += String.fromCharCode(input.peek(i)); | ||
} | ||
if (potentialLang.match(tokenRegEx)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't currently show the
createdTime
, so these props could be removed.If you want to show the
createdTime
somewhere, then the prop could be kept