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

pass Transaction to validFor #23

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 5 additions & 5 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class ActiveResult extends ActiveSource {
type == "delete" && cur(tr.startState) == this.from)
return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? State.Pending : State.Inactive)
let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos)
if (checkValid(result.validFor, tr.state, from, to))
if (checkValid(result.validFor, tr, from, to))
return new ActiveResult(this.source, explicitPos, result, from, to)
if (result.update &&
(result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
Expand All @@ -279,10 +279,10 @@ export class ActiveResult extends ActiveSource {
}

function checkValid(validFor: undefined | RegExp | ((text: string, from: number, to: number, state: EditorState) => boolean),
state: EditorState, from: number, to: number) {
if (!validFor) return false
let text = state.sliceDoc(from, to)
return typeof validFor == "function" ? validFor(text, from, to, state) : ensureAnchor(validFor, true).test(text)
tr: Transaction, from: number, to: number) {
if (!validFor || tr.isUserEvent("input.complete")) return false
let text = tr.state.sliceDoc(from, to)
return typeof validFor == "function" ? validFor(text, from, to, tr.state) : ensureAnchor(validFor, true).test(text)
}

export const setActiveEffect = StateEffect.define<readonly ActiveSource[]>({
Expand Down