fix: include more search results in linking autocomplete menu

This commit is contained in:
Mo
2022-11-24 09:30:13 -06:00
parent 75303b5eb8
commit 2e517c985d
5 changed files with 30 additions and 20 deletions

View File

@@ -9,7 +9,6 @@ import { ListableContentItem } from '../Types/ListableContentItem'
import { DailyItemsDay } from './DailyItemsDaySection' import { DailyItemsDay } from './DailyItemsDaySection'
import { ListItemTitle } from '../ListItemTitle' import { ListItemTitle } from '../ListItemTitle'
import { EmptyPlaceholderBars } from './EmptyPlaceholderBars' import { EmptyPlaceholderBars } from './EmptyPlaceholderBars'
import { isMobileScreen } from '@/Utils'
type DaySquareProps = { type DaySquareProps = {
day: number day: number
@@ -73,7 +72,7 @@ export const DailyItemCell = forwardRef(
{!item && ( {!item && (
<div className="w-full"> <div className="w-full">
<div className="break-word mr-2 font-semibold">{formatDateAndTimeForNote(section.date, false)}</div> <div className="break-word mr-2 font-semibold">{formatDateAndTimeForNote(section.date, false)}</div>
<EmptyPlaceholderBars rows={isMobileScreen() ? 2 : 4} /> <EmptyPlaceholderBars rows={1} />
</div> </div>
)} )}
</div> </div>

View File

@@ -95,7 +95,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
private protectionTimeoutId: ReturnType<typeof setTimeout> | null = null private protectionTimeoutId: ReturnType<typeof setTimeout> | null = null
private noteViewElementRef: RefObject<HTMLDivElement> private noteViewElementRef: RefObject<HTMLDivElement>
private editorContentRef: RefObject<HTMLDivElement> private editorContentRef: RefObject<HTMLDivElement>
private plainEditorRef?: RefObject<PlainEditorInterface> private plainEditorRef?: PlainEditorInterface
constructor(props: NoteViewProps) { constructor(props: NoteViewProps) {
super(props, props.application) super(props, props.application)
@@ -231,6 +231,18 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
} }
} }
setPlainEditorRef = (ref: PlainEditorInterface | undefined) => {
this.plainEditorRef = ref || undefined
if (!this.plainEditorRef) {
return
}
if (this.controller.isTemplateNote && this.controller.templateNoteOptions?.autofocusBehavior === 'editor') {
this.plainEditorRef.focus()
}
}
override componentDidUpdate(_prevProps: NoteViewProps, prevState: State): void { override componentDidUpdate(_prevProps: NoteViewProps, prevState: State): void {
if ( if (
this.state.showProtectedWarning != undefined && this.state.showProtectedWarning != undefined &&
@@ -569,7 +581,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
} }
currentTarget.blur() currentTarget.blur()
this.plainEditorRef?.current?.focus() this.plainEditorRef?.focus()
} }
onTitleChange: ChangeEventHandler<HTMLInputElement> = ({ currentTarget }) => { onTitleChange: ChangeEventHandler<HTMLInputElement> = ({ currentTarget }) => {
@@ -944,7 +956,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
<PlainEditor <PlainEditor
application={this.application} application={this.application}
spellcheck={this.state.spellcheck} spellcheck={this.state.spellcheck}
ref={this.plainEditorRef} ref={(ref) => this.setPlainEditorRef(ref || undefined)}
controller={this.controller} controller={this.controller}
locked={this.state.noteLocked} locked={this.state.noteLocked}
onFocus={this.onPlainFocus} onFocus={this.onPlainFocus}

View File

@@ -33,7 +33,7 @@ export type PlainEditorInterface = {
} }
export const PlainEditor = forwardRef<PlainEditorInterface, Props>( export const PlainEditor = forwardRef<PlainEditorInterface, Props>(
({ application, spellcheck, controller, locked, onFocus, onBlur }: Props, ref) => { ({ application, spellcheck, controller, locked, onFocus, onBlur }, ref) => {
const [editorText, setEditorText] = useState<string | undefined>() const [editorText, setEditorText] = useState<string | undefined>()
const [textareaUnloading, setTextareaUnloading] = useState(false) const [textareaUnloading, setTextareaUnloading] = useState(false)
const [lineHeight, setLineHeight] = useState<EditorLineHeight | undefined>() const [lineHeight, setLineHeight] = useState<EditorLineHeight | undefined>()
@@ -239,7 +239,7 @@ export const PlainEditor = forwardRef<PlainEditorInterface, Props>(
onFocus={onContentFocus} onFocus={onContentFocus}
onBlur={onContentBlur} onBlur={onContentBlur}
readOnly={locked} readOnly={locked}
ref={(ref) => ref && onRef(ref)} ref={onRef}
spellCheck={spellcheck} spellCheck={spellcheck}
value={editorText} value={editorText}
className={classNames( className={classNames(

View File

@@ -610,7 +610,7 @@ export class ItemListController extends AbstractViewController implements Intern
async createNewNoteController( async createNewNoteController(
title?: string, title?: string,
createdAt?: Date, createdAt?: Date,
autofocusBehavior?: TemplateNoteViewAutofocusBehavior, autofocusBehavior: TemplateNoteViewAutofocusBehavior = 'editor',
) { ) {
const selectedTag = this.navigationController.selected const selectedTag = this.navigationController.selected

View File

@@ -6,8 +6,12 @@ import { isSearchResultExistingTag } from './isSearchResultExistingTag'
import { ItemLink } from './ItemLink' import { ItemLink } from './ItemLink'
import { LinkableItem } from './LinkableItem' import { LinkableItem } from './LinkableItem'
const ResultLimitPerContentType = 5 const MaxLinkedResults = 50
const MaxLinkedResults = 20
function resultLimitForSearchQuery(query: string): number {
const limitPerContentType = 10
return Math.max(limitPerContentType, query.length * 3)
}
export function getLinkingSearchResults( export function getLinkingSearchResults(
searchQuery: string, searchQuery: string,
@@ -77,27 +81,22 @@ export function getLinkingSearchResults(
const enforceResultLimit = options.contentType == null const enforceResultLimit = options.contentType == null
const limitPerContentType = resultLimitForSearchQuery(searchQuery)
if ( if (
item.content_type === ContentType.Tag && item.content_type === ContentType.Tag &&
(!enforceResultLimit || (!enforceResultLimit || (unlinkedTags.length < limitPerContentType && item.content_type === ContentType.Tag))
(unlinkedTags.length < ResultLimitPerContentType && item.content_type === ContentType.Tag))
) { ) {
unlinkedTags.push(item) unlinkedTags.push(item)
continue continue
} }
if ( if (item.content_type === ContentType.Note && (!enforceResultLimit || unlinkedNotes.length < limitPerContentType)) {
item.content_type === ContentType.Note &&
(!enforceResultLimit || unlinkedNotes.length < ResultLimitPerContentType)
) {
unlinkedNotes.push(item) unlinkedNotes.push(item)
continue continue
} }
if ( if (item.content_type === ContentType.File && (!enforceResultLimit || unlinkedFiles.length < limitPerContentType)) {
item.content_type === ContentType.File &&
(!enforceResultLimit || unlinkedFiles.length < ResultLimitPerContentType)
) {
unlinkedFiles.push(item) unlinkedFiles.push(item)
continue continue
} }