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

Render quote characters outside of the text pills #9167

Closed
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const widgetDefinition = defineWidget(WidgetInput.isAstOrPlaceholder, {

<template>
<!-- See comment in GraphNode next to dragPointer definition about stopping pointerdown -->
<EnsoTextInputWidget v-model="value" class="WidgetText r-24" @pointerdown.stop />
'<EnsoTextInputWidget v-model="value" class="WidgetText r-24" @pointerdown.stop />'
</template>

<style scoped>
Expand Down
40 changes: 9 additions & 31 deletions app/gui2/src/components/widgets/EnsoTextInputWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const props = defineProps<{
}>()
const emit = defineEmits<{ 'update:modelValue': [modelValue: string] }>()

const separatorRegex = /(^('''|"""|['"]))|(('''|"""|['"])$)/g

// Edited value reflects the `modelValue`, but does not update it until the user defocuses the field.
const editedValue = ref(props.modelValue)
const editedValue = ref(unescape(props.modelValue.replace(separatorRegex, '')))
watch(
() => props.modelValue,
(newValue) => {
editedValue.value = newValue
},
(newValue) => (editedValue.value = unescape(newValue.replace(separatorRegex, ''))),
)

const inputNode = ref<HTMLInputElement>()
Expand All @@ -30,15 +30,11 @@ const inputMeasurements = computed(() => {
})

const inputStyle = computed<StyleValue>(() => {
if (inputNode.value == null) {
return {}
}
const value = `${editedValue.value}`
if (inputNode.value == null) return {}
const value = editedValue.value
const measurements = inputMeasurements.value
const width = getTextWidthByFont(value, measurements.font)
return {
width: `${width}px`,
}
return { width: `${width}px` }
})

/** To prevent other elements from stealing mouse events (which breaks blur),
Expand All @@ -55,24 +51,6 @@ function setupAutoBlur() {
}
window.addEventListener('pointerdown', callback, options)
}

const separators = /(^('''|"""|['"]))|(('''|"""|['"])$)/g
/** Display the value in a more human-readable form for easier editing. */
function prepareForEditing() {
editedValue.value = unescape(editedValue.value.replace(separators, ''))
}

function focus() {
setupAutoBlur()
prepareForEditing()
}

const escapedValue = computed(() => `'${escape(editedValue.value)}'`)

function blur() {
emit('update:modelValue', escapedValue.value)
editedValue.value = props.modelValue
}
</script>

<template>
Expand All @@ -88,8 +66,8 @@ function blur() {
class="value"
:style="inputStyle"
@keydown.enter.stop="($event.target as HTMLInputElement).blur()"
@focus="focus"
@blur="blur"
@focus="setupAutoBlur"
@blur="emit('update:modelValue', `'${escape(editedValue)}'`)"
/>
</div>
</template>
Expand Down
Loading