diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-07-05 17:17:59 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-07-05 17:17:59 +0200 |
| commit | 349ee65db67aa0d28d3861530e8e7e1b5cc27c48 (patch) | |
| tree | 0d2703eb7f2c844e5ae2b4103cae664f6871ee88 /animism-align/frontend/views/align/align.util.js | |
| parent | 9ceecc1561fbd7d8d704b2f491957eebdb202ab7 (diff) | |
selected paragraph actions
Diffstat (limited to 'animism-align/frontend/views/align/align.util.js')
| -rw-r--r-- | animism-align/frontend/views/align/align.util.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/animism-align/frontend/views/align/align.util.js b/animism-align/frontend/views/align/align.util.js index 32cbc35..ce72aef 100644 --- a/animism-align/frontend/views/align/align.util.js +++ b/animism-align/frontend/views/align/align.util.js @@ -26,3 +26,27 @@ export const timeToPosition = (ts, { start_ts, zoom, duration }) => { } return (ts - timeMin) / timeWidth * height } + +export const getFirstPunctuationMarkIndex = text => { + return Math.min( + text.indexOf('. '), + text.indexOf('? '), + text.indexOf('! '), + text.indexOf('." '), + text.indexOf('?" '), + text.indexOf('!" '), + text.indexOf('.” '), + text.indexOf('?” '), + text.indexOf('!” '), + ) + 1 +} + +export const cutFirstSentence = text => { + const textToCrop = text.trim().replace("\n", " ").split("\n")[0] + let cropIndex = getFirstPunctuationMarkIndex(textToCrop) + if (!cropIndex) cropIndex = textToCrop.length + const croppedText = textToCrop.substr(0, cropIndex).trim() + const updatedText = text.trim().replace(croppedText, '').trim() + actions.site.updateText(updatedText) + return croppedText +} |
