Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions src/html-duration-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,21 @@ export default (function () {
*/

const getCursorSelection = (event, hideSeconds) => {
const {
target: {selectionStart, selectionEnd, value},
} = event;
const hourMarker = value.indexOf(':');
const minuteMarker = value.lastIndexOf(':');
let cursorSelection;
// The cursor selection is: hours
if (selectionStart <= hourMarker) {
cursorSelection = 'hours';
} else if (hideSeconds || selectionStart <= minuteMarker) {
// The cursor selection is: minutes
cursorSelection = 'minutes';
} else if (!hideSeconds && selectionStart > minuteMarker) {
// The cursor selection is: seconds
cursorSelection = 'seconds';
}
const content = value.slice(selectionStart, selectionEnd);
return {cursorSelection, hideSeconds, hourMarker, minuteMarker, content};
};
const { selectionStart, selectionEnd, value } = event.target;
const hourMarker = value.indexOf(':');
const minuteMarker = value.lastIndexOf(':');
let cursorSelection;
if (selectionStart <= hourMarker) {
cursorSelection = 'hours';
} else if (hideSeconds || selectionStart <= minuteMarker) {
cursorSelection = 'minutes';
} else {
cursorSelection = 'seconds';
}
const content = value.slice(selectionStart, selectionEnd);
return { cursorSelection, hideSeconds, hourMarker, minuteMarker, content };
};


/**
* Set the 'data-adjustment-factor' attribute for a picker
Expand Down