mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-07-19 02:56:14 +01:00
Encoding Fixes
This commit is contained in:
+22
-5
@@ -476,21 +476,38 @@
|
||||
|
||||
#define gender2text(gender) capitalize(gender)
|
||||
|
||||
/// Used to get a properly sanitized input, of max_length
|
||||
/// no_trim is self explanatory but it prevents the input from being trimed if you intend to parse newlines or whitespace.
|
||||
/**
|
||||
* Used to get a properly sanitized input. Returns null if cancel is pressed.
|
||||
*
|
||||
* Arguments
|
||||
** user - Target of the input prompt.
|
||||
** message - The text inside of the prompt.
|
||||
** title - The window title of the prompt.
|
||||
** max_length - If you intend to impose a length limit - default is 1024.
|
||||
** no_trim - Prevents the input from being trimmed if you intend to parse newlines or whitespace.
|
||||
*/
|
||||
/proc/stripped_input(mob/user, message = "", title = "", default = "", max_length=MAX_MESSAGE_LEN, no_trim=FALSE)
|
||||
var/user_input = input(user, message, title, default) as text|null
|
||||
if(isnull(user_input))
|
||||
if(isnull(user_input)) // User pressed cancel
|
||||
return
|
||||
if(no_trim)
|
||||
return copytext(html_encode(user_input), 1, max_length)
|
||||
else
|
||||
return trim(html_encode(user_input), max_length) //trim is "outside" because html_encode can expand single symbols into multiple symbols (such as turning < into <)
|
||||
|
||||
// Used to get a properly sanitized multiline input, of max_length
|
||||
/**
|
||||
* Used to get a properly sanitized input in a larger box. Works very similarly to stripped_input.
|
||||
*
|
||||
* Arguments
|
||||
** user - Target of the input prompt.
|
||||
** message - The text inside of the prompt.
|
||||
** title - The window title of the prompt.
|
||||
** max_length - If you intend to impose a length limit - default is 1024.
|
||||
** no_trim - Prevents the input from being trimmed if you intend to parse newlines or whitespace.
|
||||
*/
|
||||
/proc/stripped_multiline_input(mob/user, message = "", title = "", default = "", max_length=MAX_MESSAGE_LEN, no_trim=FALSE)
|
||||
var/user_input = input(user, message, title, default) as message|null
|
||||
if(isnull(user_input))
|
||||
if(isnull(user_input)) // User pressed cancel
|
||||
return
|
||||
if(no_trim)
|
||||
return copytext(html_encode(user_input), 1, max_length)
|
||||
|
||||
@@ -221,7 +221,8 @@
|
||||
"title" = title,
|
||||
"status" = status,
|
||||
"interface" = interface,
|
||||
"refreshing" = refreshing,
|
||||
//"refreshing" = refreshing,
|
||||
"refreshing" = FALSE,
|
||||
"map" = (using_map && using_map.path) ? using_map.path : "Unknown",
|
||||
"mapZLevel" = map_z_level,
|
||||
"window" = list(
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* * encode - Toggling this determines if input is filtered via html_encode. Setting this to FALSE gives raw input.
|
||||
* * timeout - The timeout of the textbox, after which the modal will close and qdel itself. Set to zero for no timeout.
|
||||
*/
|
||||
/proc/tgui_input_text(mob/user, message = "", title = "Text Input", default, max_length = MAX_MESSAGE_LEN, multiline = FALSE, encode = TRUE, timeout = 0)
|
||||
/proc/tgui_input_text(mob/user, message = "", title = "Text Input", default, max_length = MAX_MESSAGE_LEN, multiline = FALSE, encode = FALSE, timeout = 0)
|
||||
if (istext(user))
|
||||
stack_trace("tgui_input_text() received text for user instead of mob")
|
||||
return
|
||||
@@ -150,7 +150,7 @@
|
||||
/datum/tgui_input_text/proc/set_entry(entry)
|
||||
if(!isnull(entry))
|
||||
var/converted_entry = encode ? html_encode(entry) : entry
|
||||
converted_entry = readd_quotes(converted_entry)
|
||||
//converted_entry = readd_quotes(converted_entry)
|
||||
src.entry = trim(converted_entry, max_length)
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,12 +9,12 @@ import { classes } from 'common/react';
|
||||
import { Component, createRef } from 'inferno';
|
||||
import { Box } from './Box';
|
||||
import { toInputValue } from './Input';
|
||||
import { KEY_ESCAPE } from 'common/keycodes';
|
||||
import { KEY_ENTER, KEY_ESCAPE, KEY_TAB } from 'common/keycodes';
|
||||
|
||||
export class TextArea extends Component {
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
this.textareaRef = createRef();
|
||||
this.textareaRef = props.innerRef || createRef();
|
||||
this.fillerRef = createRef();
|
||||
this.state = {
|
||||
editing: false,
|
||||
@@ -54,19 +54,46 @@ export class TextArea extends Component {
|
||||
};
|
||||
this.handleKeyDown = e => {
|
||||
const { editing } = this.state;
|
||||
const { onKeyDown } = this.props;
|
||||
if (e.keyCode === KEY_ESCAPE) {
|
||||
const { onChange, onInput, onEnter, onKeyDown } = this.props;
|
||||
if (e.keyCode === KEY_ENTER) {
|
||||
this.setEditing(false);
|
||||
e.target.value = toInputValue(this.props.value);
|
||||
e.target.blur();
|
||||
if (onChange) {
|
||||
onChange(e, e.target.value);
|
||||
}
|
||||
if (onInput) {
|
||||
onInput(e, e.target.value);
|
||||
}
|
||||
if (onEnter) {
|
||||
onEnter(e, e.target.value);
|
||||
}
|
||||
if (this.props.selfClear) {
|
||||
e.target.value = '';
|
||||
e.target.blur();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (e.keyCode === KEY_ESCAPE) {
|
||||
if (this.props.onEscape) {
|
||||
this.props.onEscape(e);
|
||||
}
|
||||
this.setEditing(false);
|
||||
if (this.props.selfClear) {
|
||||
e.target.value = '';
|
||||
} else {
|
||||
e.target.value = toInputValue(this.props.value);
|
||||
e.target.blur();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!editing) {
|
||||
this.setEditing(true);
|
||||
}
|
||||
if (onKeyDown) {
|
||||
onKeyDown(e, e.target.value);
|
||||
}
|
||||
if (!dontUseTabForIndent) {
|
||||
const keyCode = e.keyCode || e.which;
|
||||
if (keyCode === 9) {
|
||||
if (keyCode === KEY_TAB) {
|
||||
e.preventDefault();
|
||||
const { value, selectionStart, selectionEnd } = e.target;
|
||||
e.target.value = (
|
||||
@@ -76,9 +103,6 @@ export class TextArea extends Component {
|
||||
e.target.selectionEnd = selectionStart + 1;
|
||||
}
|
||||
}
|
||||
if (onKeyDown) {
|
||||
onKeyDown(e, e.target.value);
|
||||
}
|
||||
};
|
||||
this.handleFocus = e => {
|
||||
const { editing } = this.state;
|
||||
@@ -110,11 +134,10 @@ export class TextArea extends Component {
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
const { editing } = this.state;
|
||||
const prevValue = prevProps.value;
|
||||
const nextValue = this.props.value;
|
||||
const input = this.textareaRef.current;
|
||||
if (input && !editing && prevValue !== nextValue) {
|
||||
if (input && typeof nextValue === "string" && prevValue !== nextValue) {
|
||||
input.value = toInputValue(nextValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Loader } from './common/Loader';
|
||||
import { InputButtons } from './common/InputButtons';
|
||||
import { useBackend, useLocalState } from '../backend';
|
||||
import { KEY_ENTER, KEY_ESCAPE } from '../../common/keycodes';
|
||||
import { Box, Section, Stack, TextArea } from '../components';
|
||||
import { Window } from '../layouts';
|
||||
|
||||
@@ -48,14 +47,10 @@ export const TextInputModal = (_, context) => {
|
||||
<Window title={title} width={325} height={windowHeight}>
|
||||
{timeout && <Loader value={timeout} />}
|
||||
<Window.Content
|
||||
onKeyDown={(event) => {
|
||||
const keyCode = window.event ? event.which : event.keyCode;
|
||||
if (keyCode === KEY_ENTER) {
|
||||
act('submit', { entry: input });
|
||||
}
|
||||
if (keyCode === KEY_ESCAPE) {
|
||||
act('cancel');
|
||||
}
|
||||
onEscape={() => act('cancel')}
|
||||
onEnter={(event) => {
|
||||
act('submit', { entry: input });
|
||||
event.preventDefault();
|
||||
}}>
|
||||
<Section fill>
|
||||
<Stack fill vertical>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user