Skip to content

Commit

Permalink
requied changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nk183 committed Apr 5, 2022
1 parent b7312f2 commit 1454477
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
33 changes: 31 additions & 2 deletions mathesar_ui/src/component-library/text-area/TextArea.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import BaseInput from '@mathesar-component-library-dir/common/base-components/BaseInput.svelte';
let textareaRef: HTMLTextAreaElement ;
// Id for the input
export let id: string | undefined = undefined;
Expand All @@ -10,6 +11,33 @@
let classes = '';
export { classes as class };
export let addNewLineOnAllEnterKeyCombinations = false
export let handleInputKeydown : (e: KeyboardEvent) => void;
// export let isNewLine : boolean = false;
function handleKeyDown(
e: KeyboardEvent,
handler: (e: KeyboardEvent) => void,
) {
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey) ) {
if(addNewLineOnAllEnterKeyCombinations){
let pos = textareaRef.selectionStart
let front = (textareaRef.value).substring(0, pos);
let back = (textareaRef.value).substring(pos, textareaRef.value.length);
textareaRef.value = front+'\n'+back;
value=textareaRef.value
pos = pos + 1;
textareaRef.selectionStart = pos;
textareaRef.selectionEnd = pos;
e.stopPropagation();
}
} else {
handler(e);
}
}
/**
* Value of the input. Use bind tag for two-way binding.
* Refer Svelte docs for more info on binding form input values.
Expand All @@ -24,9 +52,10 @@
class="input-element text-area {classes}"
{id}
{disabled}
bind:this={textareaRef}
bind:value
on:input
on:focus
on:blur
on:keydown
/>
on:keydown={(e) => handleKeyDown(e, handleInputKeydown)}
/>
16 changes: 5 additions & 11 deletions mathesar_ui/src/components/cell/cell-types/TextAreaCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@
// Db options
export let length: number | undefined = undefined;
function handleKeyDown(
e: KeyboardEvent,
handler: (e: KeyboardEvent) => void,
) {
if (e.key === 'Enter') {
e.stopPropagation();
} else {
handler(e);
}
}
let addNewLineOnAllEnterKeyCombinations :boolean = true;
</script>

<SteppedInputCell
Expand All @@ -40,7 +32,9 @@
{disabled}
bind:value
on:blur={handleInputBlur}
on:keydown={(e) => handleKeyDown(e, handleInputKeydown)}
on:keydown
{addNewLineOnAllEnterKeyCombinations}
{handleInputKeydown}
/>
</SteppedInputCell>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@
function handleKeyDown(e: KeyboardEvent) {
switch (e.key) {
case 'Enter':
if (isEditMode) {
resetEditMode();
} else {
setModeToEdit();
if(e.shiftKey){
if (isEditMode) {
resetEditMode();
} else {
setModeToEdit();
}
}
else{
if (isEditMode) {
resetEditMode();
} else {
setModeToEdit();
}
}
// Preventing default behaviour here
// Interesting problem: If this is not prevented, the textarea gets a new line break
Expand Down Expand Up @@ -153,4 +162,4 @@
-webkit-box-orient: vertical;
}
}
</style>
</style>

0 comments on commit 1454477

Please sign in to comment.