Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
228e31b
Add beginning of suggestions pop-up
MarcelRobitaille Jul 21, 2022
ad353fe
Update changelog
MarcelRobitaille Jul 25, 2022
e251629
Fix focused element without rounded corners
MarcelRobitaille Jul 25, 2022
c06138f
Fix double thick border on last element
MarcelRobitaille Jul 25, 2022
5845281
Add more horizontal padding
MarcelRobitaille Jul 25, 2022
b2c27cc
Make suggestions popup scroll
MarcelRobitaille Jul 25, 2022
3821be0
Ensure popup does not overflow to the right
MarcelRobitaille Jul 25, 2022
6a062fd
Align popup with left of #
MarcelRobitaille Jul 25, 2022
be77c73
Update popup position if line changes
MarcelRobitaille Jul 25, 2022
ca2b209
Make popup width 100% left 0 for small screens
MarcelRobitaille Jul 25, 2022
cc789e4
Make SuggestionsPopup props required
MarcelRobitaille Jul 25, 2022
8da9f6b
Make items truncate with ellipsis correctly
MarcelRobitaille Jul 25, 2022
a69a017
Implement SuggestionsPopup in EditInputField
MarcelRobitaille Jul 25, 2022
5ef9199
Remove referencePopupEnabled prop
MarcelRobitaille Jul 25, 2022
9ea8cd7
Move computed stuff and logic to Suggestion component
MarcelRobitaille Jul 25, 2022
72af37b
Make sure initially scrolled to top
MarcelRobitaille Jul 25, 2022
6041a63
Fix forgetting submit method when refactoring
MarcelRobitaille Jul 26, 2022
5e0b54d
Allow popup to be recovered on focus
MarcelRobitaille Jul 26, 2022
a2efdec
Fix suggestion selection replacing search text
MarcelRobitaille Jul 28, 2022
977f413
Add logging to track down blur/focus issue
MarcelRobitaille Jul 28, 2022
45dc785
Cancel suggestions popup on mouse caret change
MarcelRobitaille Jul 29, 2022
e30e8b5
Hide browser debug logs for builds
christianlupus Aug 5, 2022
6ec0692
Make prettier happy
christianlupus Aug 5, 2022
92d6349
Merge remote-tracking branch 'upstream/master' into 903-link-suggestions
christianlupus Aug 5, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[#1097](https://github.com/nextcloud/cookbook/pull/1097) @christianlupus
- Ordering corrected for mobile and printout versions
[#1107](https://github.com/nextcloud/cookbook/pull/1107) @christianlupus
- Less intrusive sharp popup (suggestion menu for reference autocomplete)
[#1098](https://github.com/nextcloud/cookbook/pull/1098) @MarcelRobitaille

### Fixed
- Prevent slow loading of recipes due to iteration over all files
Expand Down
15 changes: 12 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@nextcloud/moment": "^1.1.1",
"@nextcloud/router": "^2.0.0",
"@nextcloud/vue": "^5.1.0",
"caret-pos": "2.0.0",
"linkifyjs": "^3.0.1",
"lozad": "^1.16.0",
"sass": "^1.5.0",
Expand Down
81 changes: 27 additions & 54 deletions src/components/EditInputField.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<fieldset @keyup="keyPressed">
<fieldset>
<label>
{{ fieldLabel }}
</label>
Expand All @@ -8,6 +8,11 @@
ref="inputField"
v-model="content"
@input="handleInput"
@keydown="keyDown"
@keyup="handleSuggestionsPopupKeyUp"
@focus="handleSuggestionsPopupFocus"
@blur="handleSuggestionsPopupBlur"
@mouseup="handleSuggestionsPopupMouseUp"
/>
<div v-else>
<slot />
Expand All @@ -17,14 +22,31 @@
v-model="content"
:type="fieldType"
@input="handleInput"
@keydown="keyDown"
@keyup="handleSuggestionsPopupKeyUp"
@focus="handleSuggestionsPopupFocus"
@blur="handleSuggestionsPopupBlur"
@mouseup="handleSuggestionsPopupMouseUp"
/>
</div>
<SuggestionsPopup
v-if="suggestionsPopupVisible"
ref="suggestionsPopup"
v-bind="suggestionsData"
:options="filteredSuggestionOptions"
/>
</fieldset>
</template>

<script>
import SuggestionsPopup, { suggestionsPopupMixin } from "./SuggestionsPopup.vue"

export default {
name: "EditInputField",
components: {
SuggestionsPopup,
},
mixins: [suggestionsPopupMixin],
props: {
fieldLabel: {
type: String,
Expand All @@ -34,10 +56,6 @@ export default {
type: String,
default: "",
},
referencePopupEnabled: {
type: Boolean,
default: false,
},
// Value (passed in v-model)
// eslint-disable-next-line vue/require-prop-types
value: {
Expand Down Expand Up @@ -65,55 +83,10 @@ export default {
handleInput() {
this.$emit("input", this.content)
},
/**
* Catches # key down presses and opens recipe-references dialog
*/
keyPressed(e) {
// Using keyup for trigger will prevent repeat triggering if key is held down
if (this.referencePopupEnabled && e.key === "#") {
e.preventDefault()
// Check if the letter before the hash
if (this.fieldType === "markdown") {
// for reference: https://codemirror.net/doc/manual.html#api
const cursorPos = JSON.parse(
JSON.stringify(
this.$refs.inputField.editor.getCursor("start")
)
)
const prevChar = this.$refs.inputField.editor.getRange(
{ line: cursorPos.line, ch: cursorPos.ch - 2 },
{ line: cursorPos.line, ch: cursorPos.ch - 1 }
)
if (
cursorPos.ch === 1 ||
prevChar === " " ||
prevChar === "\n" ||
prevChar === "\r"
) {
// beginning of line
this.$parent.$emit("showRecipeReferencesPopup", {
context: this,
})
this.lastCursorPosition = cursorPos
}
} else {
const cursorPos = this.$refs.inputField.selectionStart
const content = this.$refs.inputField.value
const prevChar =
cursorPos > 1 ? content.charAt(cursorPos - 2) : ""
if (
cursorPos === 1 ||
prevChar === " " ||
prevChar === "\n" ||
prevChar === "\r"
) {
// Show dialog to select recipe
this.$parent.$emit("showRecipeReferencesPopup", {
context: this,
})
this.lastCursorPosition = cursorPos
}
}
keyDown(e) {
// Redirect to suggestions handler if in suggestion mode
if (this.suggestionsPopupVisible) {
this.handleSuggestionsPopupKeyDown(e)
}
},
pasteCanceled() {
Expand Down
58 changes: 29 additions & 29 deletions src/components/EditInputGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
@keyup="keyUp"
@input="handleInput"
@paste="handlePaste"
@focus="handleSuggestionsPopupFocus"
@blur="handleSuggestionsPopupBlur"
@mouseup="handleSuggestionsPopupMouseUp"
/>
<textarea
v-else-if="fieldType === 'textarea'"
Expand All @@ -28,6 +31,9 @@
@keyup="keyUp"
@input="handleInput"
@paste="handlePaste"
@focus="handleSuggestionsPopupFocus"
@blur="handleSuggestionsPopupBlur"
@mouseup="handleSuggestionsPopupMouseUp"
></textarea>
<div class="controls">
<button
Expand All @@ -51,6 +57,15 @@
@click="deleteEntry(idx)"
></button>
</div>
<SuggestionsPopup
v-if="
suggestionsPopupVisible &&
suggestionsData.fieldIndex === idx
"
ref="suggestionsPopup"
v-bind="suggestionsData"
:options="filteredSuggestionOptions"
/>
</li>
</ul>
<button class="button add-list-item" @click="addNewEntry()">
Expand All @@ -60,6 +75,8 @@
</template>

<script>
import SuggestionsPopup, { suggestionsPopupMixin } from "./SuggestionsPopup.vue"

const linesMatchAtPosition = (lines, i) =>
lines.every((line) => line[i] === lines[0][i])
const findCommonPrefix = (lines) => {
Expand All @@ -82,6 +99,10 @@ const findCommonPrefix = (lines) => {

export default {
name: "EditInputGroup",
components: {
SuggestionsPopup,
},
mixins: [suggestionsPopupMixin],
props: {
value: {
type: Array,
Expand All @@ -108,10 +129,6 @@ export default {
type: Boolean,
default: false,
},
referencePopupEnabled: {
type: Boolean,
default: false,
},
},
data() {
return {
Expand Down Expand Up @@ -268,6 +285,12 @@ export default {
return
}

// Redirect to suggestions handler if in suggestion mode
if (this.suggestionsPopupVisible) {
this.handleSuggestionsPopupKeyDown(e)
return
}

// Allow new lines with shift key
if (e.shiftKey) {
// Do nothing here, user wants a line break
Expand Down Expand Up @@ -318,38 +341,14 @@ export default {
return
}

// Only do anything for enter or # keys
if (!(this.referencePopupEnabled && e.key === "#")) {
return
}

// Get the index of the pressed list item
const $li = e.currentTarget.closest("li")
const $ul = $li.closest("ul")
const $pressedLiIndex = Array.prototype.indexOf.call(
$ul.childNodes,
$li
)

// Get the position of the cursor and the content of the input
const elm = this.$refs["list-field"][$pressedLiIndex]
const cursorPos = elm.selectionStart
const content = elm.value

// Show the popup only if the # was inserted at the very
// beggining of the input or after any whitespace character
if (
!(cursorPos === 1 || /\s/.test(content.charAt(cursorPos - 2)))
) {
return
}

// Show dialog to select recipe
this.$parent.$emit("showRecipeReferencesPopup", {
context: this,
})
this.lastFocusedFieldIndex = $pressedLiIndex
this.lastCursorPosition = cursorPos
this.handleSuggestionsPopupKeyUp(e)
},
moveEntryDown(index) {
if (index >= this.buffer.length - 1) {
Expand Down Expand Up @@ -421,6 +420,7 @@ button {
}

fieldset {
position: relative;
width: 100%;
margin-bottom: 1em;
}
Expand Down
Loading