-
Notifications
You must be signed in to change notification settings - Fork 91
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
Feat/4750 Make code type fields copyable #5395
Changes from 2 commits
dd382e0
ca0d4b0
81960db
0a70ed5
8b3360d
bb24bca
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 | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,21 @@ | ||||||
<template> | ||||||
<NodeViewWrapper as="div" :data-mode="viewMode" class="code-block"> | ||||||
<div v-if="isEditable" class="code-block-header"> | ||||||
<div class="code-block-header"> | ||||||
<div class="view-switch"> | ||||||
<NcActions :aria-label="t('text', 'Code block options')"> | ||||||
<NcActions :aria-label="t('text', 'Copy code block')"> | ||||||
<NcActionButton v-if="hasCode" | ||||||
:aria-label="t('text', 'Copy code')" | ||||||
:close-after-click="false" | ||||||
@click="copyCode"> | ||||||
<template #icon> | ||||||
<Check v-if="copySuccess" :size="20" /> | ||||||
<NcLoadingIcon v-else-if="copyLoading" :size="20" /> | ||||||
<ContentCopy v-else :size="20" /> | ||||||
</template> | ||||||
</NcActionButton> | ||||||
</NcActions> | ||||||
|
||||||
<NcActions v-if="isEditable" :aria-label="t('text', 'Code block options')"> | ||||||
<NcActionInput :label="t('text', 'Code block language')" | ||||||
:value="type" | ||||||
:show-trailing-button="false" | ||||||
|
@@ -59,7 +72,7 @@ | |||||
<script> | ||||||
import debounce from 'debounce' | ||||||
import { NodeViewWrapper, NodeViewContent } from '@tiptap/vue-2' | ||||||
import { NcActions, NcActionButton, NcActionInput, NcActionLink, NcActionSeparator } from '@nextcloud/vue' | ||||||
import { NcActions, NcActionButton, NcActionInput, NcActionLink, NcActionSeparator, NcLoadingIcon } from '@nextcloud/vue' | ||||||
import mermaid from 'mermaid' | ||||||
import { v4 as uuidv4 } from 'uuid' | ||||||
|
||||||
|
@@ -68,13 +81,19 @@ import CodeBraces from 'vue-material-design-icons/CodeBraces.vue' | |||||
import Eye from 'vue-material-design-icons/Eye.vue' | ||||||
import MarkerIcon from 'vue-material-design-icons/Marker.vue' | ||||||
import Help from 'vue-material-design-icons/Help.vue' | ||||||
import ContentCopy from 'vue-material-design-icons/ContentCopy.vue' | ||||||
import Check from 'vue-material-design-icons/Check.vue' | ||||||
|
||||||
import CopyToClipboardMixin from '../mixins/CopyToClipboardMixin.js' | ||||||
|
||||||
export default { | ||||||
// eslint-disable-next-line vue/match-component-file-name | ||||||
name: 'CodeBlockView', | ||||||
components: { | ||||||
MarkerIcon, | ||||||
ContentCopy, | ||||||
Help, | ||||||
Check, | ||||||
Eye, | ||||||
ViewSplitVertical, | ||||||
CodeBraces, | ||||||
|
@@ -83,9 +102,11 @@ export default { | |||||
NcActionInput, | ||||||
NcActionLink, | ||||||
NcActionSeparator, | ||||||
NcLoadingIcon, | ||||||
NodeViewWrapper, | ||||||
NodeViewContent, | ||||||
}, | ||||||
mixins: [CopyToClipboardMixin], | ||||||
props: { | ||||||
node: { | ||||||
type: Object, | ||||||
|
@@ -104,6 +125,9 @@ export default { | |||||
} | ||||||
}, | ||||||
computed: { | ||||||
hasCode() { | ||||||
return this.node.textContent | ||||||
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. As this is safeguarded further down, do we need this here as well?
Suggested change
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. My initial thought process was that, since it's just checking to see if there is any text content in the node (the code block has something written in it), it wouldn't matter if we used the optional chaining |
||||||
}, | ||||||
type() { | ||||||
return this.node?.attrs?.language || '' | ||||||
}, | ||||||
|
@@ -169,6 +193,9 @@ export default { | |||||
}) | ||||||
}, | ||||||
methods: { | ||||||
async copyCode() { | ||||||
await this.copyToClipboard(this.node?.textContent) | ||||||
}, | ||||||
updateLanguage(event) { | ||||||
this.updateAttributes({ | ||||||
language: event.target.value, | ||||||
|
@@ -180,6 +207,7 @@ export default { | |||||
}, | ||||||
} | ||||||
</script> | ||||||
|
||||||
<style lang="scss" scoped> | ||||||
.code-block { | ||||||
background-color: var(--color-background-dark); | ||||||
|
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.
If I remember correctly the url was in here on purpose. The idea was that if your browser cannot copy the url for you its still displaying it so you can copy it yourself.
I'm not sure how often people would need to do that. I remember that back in the days I could not copy share links because of my browser configuration and did not find a way around that.
However in this case I think it's different. I could open the link in a tab and copy the link from there - or I right click the link and select 'copy link' from the context menu.
So I'm fine with removing the url - just wanted to explain the context.