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 search config option to not match case when search panel is opened #4

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/search.ts
Expand Up @@ -18,11 +18,19 @@ interface SearchConfig {
/// Whether to position the search panel at the top of the editor
/// (the default is at the bottom).
top?: boolean

/// Whether to match case by default when the search panel is activated
/// (the default is true)
matchCase?: boolean
}

const searchConfigFacet = Facet.define<SearchConfig, Required<SearchConfig>>({
combine(configs) {
return {top: configs.some(c => c.top)}
let matchCase = configs.some(c => c.matchCase)
return {
top: configs.some(c => c.top),
matchCase: matchCase === undefined ? true : matchCase,
}
}
})

Expand Down Expand Up @@ -354,7 +362,8 @@ function createSearchPanel(view: EditorView) {
function defaultQuery(state: EditorState, fallback?: Query) {
let sel = state.selection.main
let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to)
return fallback && !selText ? fallback : new StringQuery(selText.replace(/\n/g, "\\n"), "", fallback?.caseInsensitive || false)
marcuswestin marked this conversation as resolved.
Show resolved Hide resolved
let caseInsensitive = fallback?.caseInsensitive ?? !state.facet(searchConfigFacet).matchCase
return fallback && !selText ? fallback : new StringQuery(selText.replace(/\n/g, "\\n"), "", caseInsensitive)
}

/// Make sure the search panel is open and focused.
Expand Down