Skip to content

Commit

Permalink
Merge pull request #5411 from mzimandl/release-0.16.x
Browse files Browse the repository at this point in the history
Fix handling composition mode in query input for `release-0.16.x` branch
  • Loading branch information
tomachalek authored Nov 1, 2022
2 parents b339590 + 4658f34 commit 085d3c0
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 34 deletions.
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.kontext
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM czcorpus/kontext-manatee:latest
FROM czcorpus/kontext-manatee:2.167.10

SHELL ["/bin/bash", "--login", "-c"]
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.kontext-cypress
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM czcorpus/kontext-manatee:latest
FROM czcorpus/kontext-manatee:2.167.10

SHELL ["/bin/bash", "--login", "-c"]
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.kontext-dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM czcorpus/kontext-manatee:latest
FROM czcorpus/kontext-manatee:2.167.10

SHELL ["/bin/bash", "--login", "-c"]
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.rqworker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM czcorpus/kontext-manatee:latest
FROM czcorpus/kontext-manatee:2.167.10

RUN mkdir /var/log/rq
WORKDIR /opt/kontext
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.ws
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM czcorpus/kontext-manatee:latest
FROM czcorpus/kontext-manatee:2.167.10

RUN pip3 install --upgrade pip && pip3 install aiohttp

Expand Down
9 changes: 6 additions & 3 deletions public/files/js/models/pquery/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface PqueryFormModelState {
structAttrs:Array<Kontext.AttrItem>;
paramsVisible:boolean;
posRangeNotSupported:boolean; // for structural attributes pos range makes no sense
compositionModeOn:boolean;
}

/**
Expand Down Expand Up @@ -192,7 +193,7 @@ export function newModelState(
type: 'specification',
maxNonMatchingRatio: Kontext.newFormValue('0', true)
},
type: 'partial-query'
type: 'partial-query',
}
),
2
Expand Down Expand Up @@ -222,7 +223,8 @@ export function newModelState(
attrs,
structAttrs,
paramsVisible: true,
posRangeNotSupported: defaultAttr.includes('.')
posRangeNotSupported: defaultAttr.includes('.'),
compositionModeOn: false,
};
}

Expand Down Expand Up @@ -465,7 +467,8 @@ export function storedQueryToModel(
attrs,
structAttrs,
paramsVisible: true,
posRangeNotSupported: sq.attr.includes('.')
posRangeNotSupported: sq.attr.includes('.'),
compositionModeOn: false,
}
}

Expand Down
11 changes: 11 additions & 0 deletions public/files/js/models/pquery/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ export class PqueryFormModel extends StatefulModel<PqueryFormModelState> impleme
}
);

this.addActionHandler(
QueryActions.SetCompositionMode,
action => {
this.changeState(
state => {
state.compositionModeOn = action.payload.status;
}
)
}
);

this.addActionHandler<typeof QueryActions.QueryInputMoveCursor>(
QueryActions.QueryInputMoveCursor.name,
action => {
Expand Down
1 change: 0 additions & 1 deletion public/files/js/models/query/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { Actions } from './actions';
import { Actions as ConcActions } from '../concordance/actions';
import { Actions as MainMenuActions } from '../mainMenu/actions';
import * as PluginInterfaces from '../../types/plugins';
import { TextTypesModel } from '../textTypes/main';
import { AjaxConcResponse } from '../concordance/common';
import { QueryType, AnyQuery, AdvancedQuery, SimpleQuery, parseSimpleQuery } from './query';
import { highlightSyntaxStatic } from '../cqleditor/parser';
Expand Down
58 changes: 47 additions & 11 deletions public/files/js/views/cqlEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ interface CQLEditorCoreState {
queries:{[sourceId:string]:AdvancedQuery|SimpleQuery}|unknown; // pquery block -> query
downArrowTriggersHistory:{[sourceId:string]:boolean};
cqlEditorMessages:{[sourceId:string]:Array<string>};
compositionModeOn:boolean;
}


Expand Down Expand Up @@ -151,10 +152,12 @@ export function init(dispatcher:IActionDispatcher, he:Kontext.ComponentHelpers,
this.inputKeyDownHandler = this.inputKeyDownHandler.bind(this);
this.ffKeyDownHandler = this.ffKeyDownHandler.bind(this);
this.handleSelect = this.handleSelect.bind(this);
this.handleCompositionStart = this.handleCompositionStart.bind(this);
this.handleCompositionEnd = this.handleCompositionEnd.bind(this);
this.contentEditable = new ContentEditable<HTMLPreElement>(this.props.inputRef);
}

private handleInputChange() {
private newInputDispatch() {
const [rawAnchorIdx, rawFocusIdx] = this.contentEditable.getRawSelection();
const query = this.contentEditable.extractText();

Expand All @@ -171,6 +174,35 @@ export function init(dispatcher:IActionDispatcher, he:Kontext.ComponentHelpers,
});
}

private handleInputChange() {
if (!this.props.compositionModeOn) {
this.newInputDispatch();
}
}

private handleCompositionStart() {
dispatcher.dispatch<typeof Actions.SetCompositionMode>({
name: Actions.SetCompositionMode.name,
payload: {
formType: this.props.formType,
status: true
}
});
}

private handleCompositionEnd() {
dispatcher.dispatch<typeof Actions.SetCompositionMode>({
name: Actions.SetCompositionMode.name,
payload: {
formType: this.props.formType,
status: false
}
});
// Chrome performs onCompositionEnd action after inputChange
// we have to dispatch new state here
this.newInputDispatch();
}

private findLinkParent(elm:HTMLElement):HTMLElement {
let curr = elm;
while (curr !== this.props.inputRef.current) {
Expand Down Expand Up @@ -307,16 +339,18 @@ export function init(dispatcher:IActionDispatcher, he:Kontext.ComponentHelpers,
}

private handleSelect() {
const [anchorIdx, focusIdx] = this.contentEditable.getRawSelection();
dispatcher.dispatch<typeof Actions.QueryInputSelectText>({
name: Actions.QueryInputSelectText.name,
payload: {
sourceId: this.props.sourceId,
formType: this.props.formType,
anchorIdx,
focusIdx
}
});
if (!this.props.compositionModeOn) {
const [anchorIdx, focusIdx] = this.contentEditable.getRawSelection();
dispatcher.dispatch<typeof Actions.QueryInputSelectText>({
name: Actions.QueryInputSelectText.name,
payload: {
sourceId: this.props.sourceId,
formType: this.props.formType,
anchorIdx,
focusIdx
}
});
}
}

componentDidUpdate(prevProps, prevState) {
Expand Down Expand Up @@ -361,6 +395,8 @@ export function init(dispatcher:IActionDispatcher, he:Kontext.ComponentHelpers,
contentEditable={true}
spellCheck={false}
onInput={(evt) => this.handleInputChange()}
onCompositionStart={this.handleCompositionStart}
onCompositionEnd={this.handleCompositionEnd}
onClick={this.handleEditorClick}
className="cql-input"
ref={this.props.inputRef}
Expand Down
35 changes: 21 additions & 14 deletions public/files/js/views/query/richInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,26 @@ export function init(
this.handleCompositionEnd = this.handleCompositionEnd.bind(this);
}

private newInputDispatch(evt:React.ChangeEvent<HTMLInputElement>|React.CompositionEvent<HTMLInputElement>) {
const [rawAnchorIdx, rawFocusIdx] = this.contentEditable.getRawSelection();
const query = this.contentEditable.extractText();
dispatcher.dispatch<typeof Actions.QueryInputSetQuery>({
name: Actions.QueryInputSetQuery.name,
payload: {
formType: this.props.formType,
sourceId: this.props.sourceId,
query,
rawAnchorIdx,
rawFocusIdx,
insertRange: null
}
});
}


private handleInputChange(evt:React.ChangeEvent<HTMLInputElement>) {
if (!this.props.compositionModeOn) {
const [rawAnchorIdx, rawFocusIdx] = this.contentEditable.getRawSelection();
const query = this.contentEditable.extractText();
dispatcher.dispatch<typeof Actions.QueryInputSetQuery>({
name: Actions.QueryInputSetQuery.name,
payload: {
formType: this.props.formType,
sourceId: this.props.sourceId,
query,
rawAnchorIdx,
rawFocusIdx,
insertRange: null
}
});
this.newInputDispatch(evt);
}
}

Expand Down Expand Up @@ -238,14 +242,17 @@ export function init(
});
}

private handleCompositionEnd() {
private handleCompositionEnd(evt:React.CompositionEvent<HTMLInputElement>) {
dispatcher.dispatch<typeof Actions.SetCompositionMode>({
name: Actions.SetCompositionMode.name,
payload: {
formType: this.props.formType,
status: false
}
});
// Chrome performs onCompositionEnd action after inputChange
// we have to dispatch new state here
this.newInputDispatch(evt);
}

componentDidUpdate(prevProps:RichInputProps & QueryFormModelState, _:unknown) {
Expand Down

0 comments on commit 085d3c0

Please sign in to comment.