session-id-editable-textarea

pull/751/head
Audric Ackermann 6 years ago
parent 310038ec31
commit 736cd0f652
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -126,8 +126,4 @@
el.innerHTML = sessionID; el.innerHTML = sessionID;
fx.setText(sessionID); fx.setText(sessionID);
}; };
window.Session.emptyContentEditableDivs = () => {
window.$('div[contenteditable]').html('');
};
})(); })();

@ -302,6 +302,7 @@ $session-compose-margin: 20px;
flex-shrink: 0; flex-shrink: 0;
user-select: all; user-select: all;
overflow: hidden; overflow: hidden;
resize: none;
} }
.session-button { .session-button {

@ -212,9 +212,7 @@ export class LeftPaneChannelSection extends React.Component<Props, State> {
return; return;
} }
this.setState({ channelUrlPasted: '' }, () => { this.setState({ channelUrlPasted: '' });
window.Session.emptyContentEditableDivs();
});
if (updateSearchTerm) { if (updateSearchTerm) {
updateSearchTerm(searchTerm); updateSearchTerm(searchTerm);
@ -297,11 +295,8 @@ export class LeftPaneChannelSection extends React.Component<Props, State> {
); );
} }
private handleOnPasteUrl(e: any) { private handleOnPasteUrl(value: string) {
if (e.target.innerHTML) { this.setState({ channelUrlPasted: value });
const cleanText = e.target.innerHTML.replace(/<\/?[^>]+(>|$)/g, '');
this.setState({ channelUrlPasted: cleanText });
}
} }
private handleJoinChannelButtonClick() { private handleJoinChannelButtonClick() {

@ -164,9 +164,7 @@ export class LeftPaneContactSection extends React.Component<Props, State> {
return; return;
} }
this.setState({ pubKeyPasted: '' }, () => { this.setState({ pubKeyPasted: '' });
window.Session.emptyContentEditableDivs();
});
if (updateSearchTerm) { if (updateSearchTerm) {
updateSearchTerm(searchTerm); updateSearchTerm(searchTerm);
@ -253,12 +251,8 @@ export class LeftPaneContactSection extends React.Component<Props, State> {
} }
} }
private handleRecipientSessionIDChanged(event: any) { private handleRecipientSessionIDChanged(value: string) {
if (event.target.innerHTML) { this.setState({ addContactRecipientID: value });
// remove br elements or div elements
const cleanText = event.target.innerHTML.replace(/<\/?[^>]+(>|$)/g, '');
this.setState({ addContactRecipientID: cleanText });
}
} }
private renderContacts() { private renderContacts() {

@ -197,9 +197,7 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
return; return;
} }
// reset our pubKeyPasted, we can either have a pasted sessionID or a sessionID got from a search // reset our pubKeyPasted, we can either have a pasted sessionID or a sessionID got from a search
this.setState({ pubKeyPasted: '' }, () => { this.setState({ pubKeyPasted: '' });
window.Session.emptyContentEditableDivs();
});
if (updateSearchTerm) { if (updateSearchTerm) {
updateSearchTerm(searchTerm); updateSearchTerm(searchTerm);
@ -259,12 +257,11 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
this.updateSearch(''); this.updateSearch('');
} }
private handleOnPasteSessionID(e: any) { private handleOnPasteSessionID(value: string) {
// reset our search, we can either have a pasted sessionID or a sessionID got from a search // reset our search, we can either have a pasted sessionID or a sessionID got from a search
this.updateSearch(''); this.updateSearch('');
const cleanText = e.target.innerHTML.replace(/<\/?[^>]+(>|$)/g, '');
this.setState({ pubKeyPasted: cleanText }); this.setState({ pubKeyPasted: value });
} }
private handleMessageButtonClick() { private handleMessageButtonClick() {

@ -499,19 +499,16 @@ export class RegistrationTabs extends React.Component<{}, State> {
<SessionIdEditable <SessionIdEditable
editable={contentEditable} editable={contentEditable}
placeholder={enterSessionIDHere} placeholder={enterSessionIDHere}
onChange={(e: any) => { onChange={(value: string) => {
this.onSecondDeviceSessionIDChanged(e); this.onSecondDeviceSessionIDChanged(value);
}} }}
/> />
); );
} }
private onSecondDeviceSessionIDChanged(e: any) { private onSecondDeviceSessionIDChanged(value: string) {
e.preventDefault();
const cleanText = e.target.innerHTML.replace(/<\/?[^>]+(>|$)/g, '');
const hexEncodedPubKey = cleanText;
this.setState({ this.setState({
primaryDevicePubKey: hexEncodedPubKey, primaryDevicePubKey: value,
}); });
} }

@ -5,19 +5,17 @@ interface Props {
text?: string; text?: string;
editable?: boolean; editable?: boolean;
onChange?: any; onChange?: any;
onPressEnter?: any;
} }
export class SessionIdEditable extends React.PureComponent<Props> { export class SessionIdEditable extends React.PureComponent<Props> {
private readonly inputRef: React.RefObject<HTMLInputElement>; private readonly inputRef: any;
public constructor(props: Props) { public constructor(props: Props) {
super(props); super(props);
this.inputRef = React.createRef(); this.inputRef = React.createRef();
} this.handleChange = this.handleChange.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this);
public componentWillUnmount() {
//FIXME ugly hack to empty the content editable div used on enter session ID
window.Session.emptyContentEditableDivs();
} }
public focus() { public focus() {
@ -27,22 +25,35 @@ export class SessionIdEditable extends React.PureComponent<Props> {
} }
public render() { public render() {
const { placeholder, editable, onChange, text } = this.props; const { placeholder, editable, text } = this.props;
return ( return (
<div <textarea
ref={this.inputRef} ref={this.inputRef}
className="session-id-editable" className="session-id-editable"
placeholder={placeholder} placeholder={placeholder}
contentEditable={editable} disabled={!editable}
onInput={(e: any) => { spellCheck={false}
if (editable) { onKeyDown={this.handleKeyDown}
onChange(e); onChange={this.handleChange}
} value={text}
}} />
>
{text}
</div>
); );
} }
private handleChange(e: any) {
const { editable, onChange } = this.props;
if (editable) {
onChange(e.target.value);
}
}
private handleKeyDown(e: any) {
const { editable, onPressEnter } = this.props;
if (editable && e.keyCode === 13) {
e.preventDefault();
// tslint:disable-next-line: no-unused-expression
onPressEnter && onPressEnter();
}
}
} }

Loading…
Cancel
Save