Skip to content
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

Add Date shortcut ISO 8601 format as an option in preference #3094

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,33 @@ export default class CodeEditor extends React.Component {
// Do nothing
},
[translateHotkey(hotkey.insertDate)]: function (cm) {
const dateNow = new Date()
if (self.props.dateFormatISO8601) {
cm.replaceSelection(dateNow.toISOString().split('T')[0])
} else {
cm.replaceSelection(dateNow.toLocaleDateString())
}
},
'Cmd-/': function (cm) {
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 you should remove the code for Cmd-/ and Shift-Ctrl-/ and replace that with [translateHotkey(hotkey.insertDateTime)]. You code should be something like this:

[translateHotkey(hotkey.insertDateTime)]: function (cm) {
  const dateNow = new Date()
  if (self.props.dateFormatISO8601) {
       cm.replaceSelection(dateNow.toISOString())
  } else {
       cm.replaceSelection(dateNow.toLocaleString())
  }
}

if (global.process.platform !== 'darwin') { return }
const dateNow = new Date()
cm.replaceSelection(dateNow.toLocaleDateString())
},
[translateHotkey(hotkey.insertDateTime)]: function (cm) {
'Shift-Ctrl-/': function (cm) {
if (global.process.platform === 'darwin') { return }
const dateNow = new Date()
cm.replaceSelection(dateNow.toLocaleString())
if (self.props.dateFormatISO8601) {
cm.replaceSelection(dateNow.toISOString())
} else {
cm.replaceSelection(dateNow.toLocaleString())
}
},
'Shift-Cmd-/': function (cm) {
if (global.process.platform !== 'darwin') { return }
[translateHotkey(hotkey.insertDateTime)]: function (cm) {
const dateNow = new Date()
cm.replaceSelection(dateNow.toLocaleString())
}
},
Enter: 'boostNewLineAndIndentContinueMarkdownList',
'Ctrl-C': cm => {
Expand Down
1 change: 1 addition & 0 deletions browser/components/MarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class MarkdownEditor extends React.Component {
switchPreview={config.editor.switchPreview}
enableMarkdownLint={config.editor.enableMarkdownLint}
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
dateFormatISO8601={config.editor.dateFormatISO8601}
prettierConfig={config.editor.prettierConfig}
deleteUnusedAttachments={config.editor.deleteUnusedAttachments}
/>
Expand Down
1 change: 1 addition & 0 deletions browser/components/MarkdownSplitEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class MarkdownSplitEditor extends React.Component {
switchPreview={config.editor.switchPreview}
enableMarkdownLint={config.editor.enableMarkdownLint}
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
dateFormatISO8601={config.editor.dateFormatISO8601}
deleteUnusedAttachments={config.editor.deleteUnusedAttachments}
/>
<div styleName='slider' style={{left: this.state.codeEditorWidthInPercent + '%'}} onMouseDown={e => this.handleMouseDown(e)} >
Expand Down
1 change: 1 addition & 0 deletions browser/main/Detail/SnippetNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ class SnippetNoteDetail extends React.Component {
enableSmartPaste={config.editor.enableSmartPaste}
hotkey={config.hotkey}
autoDetect={autoDetect}
dateFormatISO8601={config.editor.dateFormatISO8601}
/>
}
</div>
Expand Down
1 change: 1 addition & 0 deletions browser/main/lib/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const DEFAULT_CONFIG = {
enableSmartPaste: false,
enableMarkdownLint: false,
customMarkdownLintConfig: DEFAULT_MARKDOWN_LINT_CONFIG,
dateFormatISO8601: false,
prettierConfig: ` {
"trailingComma": "es5",
"tabWidth": 4,
Expand Down
12 changes: 12 additions & 0 deletions browser/main/modals/PreferencesModal/UiTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class UiTab extends React.Component {
enableSmartPaste: this.refs.enableSmartPaste.checked,
enableMarkdownLint: this.refs.enableMarkdownLint.checked,
customMarkdownLintConfig: this.customMarkdownLintConfigCM.getCodeMirror().getValue(),
dateFormatISO8601: this.refs.dateFormatISO8601.checked,
prettierConfig: this.prettierConfigCM.getCodeMirror().getValue(),
deleteUnusedAttachments: this.refs.deleteUnusedAttachments.checked
},
Expand Down Expand Up @@ -629,6 +630,17 @@ class UiTab extends React.Component {
</label>
</div>

<div styleName='group-checkBoxSection'>
<label>
<input onChange={(e) => this.handleUIChange(e)}
checked={this.state.config.editor.dateFormatISO8601}
ref='dateFormatISO8601'
type='checkbox'
/>&nbsp;
{i18n.__('Date shortcut use iso 8601 format')}
</label>
</div>

<div styleName='group-section'>
<div styleName='group-section-label'>
{i18n.__('Matching character pairs')}
Expand Down