Skip to content

Commit fb805fe

Browse files
implemented optimal line length feature.
1 parent 377d304 commit fb805fe

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,17 @@ <h4 class="modal-title custom-modal-title">Preferences</h4>
299299
</div>
300300

301301
<div class="form-group">
302-
<label class="control-label col-sm-6 col-md-6" for="writeDirection">Direction</label>
302+
<label class="control-label col-sm-6 col-md-6" for="optimalLineLength">Optimal line length</label>
303+
<div class="col-sm-6 col-md-4">
304+
<select name="optimalLineLength" id="optimalLineLength" class="form-control">
305+
<option value="No">No</option>
306+
<option value="Yes">Yes</option>
307+
</select>
308+
</div>
309+
</div>
310+
311+
<div class="form-group">
312+
<label class="control-label col-sm-6 col-md-6" for="writeDirection">Writing direction</label>
303313
<div class="col-sm-6 col-md-4">
304314
<select name="writeDirection" id="writeDirection" class="form-control">
305315
<option value="ltr">Left to right</option>

js/app.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ it's recommended that you take a backup of your notes more often using the
2323
const lightMetaColor = '#4d4d4d';
2424
const metaThemeColor = document.querySelector('meta[name=theme-color]');
2525
const { notepad, state, setState, removeState, get } = selector();
26+
const optimalLineLengthPadding = '15px 15vw 40px';
2627

2728
const editorConfig = {
2829
defaultFontSize: 18,
2930
defaultLineHeight: 26,
3031
defaultFontWeight: 'normal',
3132
defaultShowWordCountPill: 'Yes',
32-
defaultWriteDirection: 'ltr'
33+
defaultWriteDirection: 'ltr',
34+
defaultOptimalLineLength: 'No',
35+
defaultOptimalLineLengthPadding: '15px 15px 40px'
3336
};
3437

3538
const themeConfig = {
@@ -87,6 +90,20 @@ it's recommended that you take a backup of your notes more often using the
8790
resetWriteDirection(editorConfig.defaultWriteDirection);
8891
}
8992

93+
if (state.userChosenOptimalLineLengthSelected) {
94+
const textArea = document.getElementById('note');
95+
96+
if (state.userChosenOptimalLineLengthSelected === 'Yes') {
97+
textArea.style.padding = optimalLineLengthPadding;
98+
} else {
99+
textArea.style.padding = editorConfig.defaultOptimalLineLengthPadding;
100+
}
101+
102+
notepad.optimalLineLength.val(state.userChosenOptimalLineLengthSelected);
103+
} else {
104+
resetOptimalLineLength(editorConfig.defaultOptimalLineLengthPadding, editorConfig.defaultOptimalLineLength);
105+
}
106+
90107
if (state.mode && state.mode === 'dark') {
91108
enableDarkMode(lightmodeText, darkMetaColor, metaThemeColor);
92109
} else {
@@ -165,6 +182,20 @@ it's recommended that you take a backup of your notes more often using the
165182
setState('userChosenWordCountPillSelected', showWordCountPillSelected);
166183
});
167184

185+
notepad.optimalLineLength.on('change', function (e) {
186+
const optimalLineLengthSelected = this.value;
187+
188+
const textArea = document.getElementById('note');
189+
190+
if (optimalLineLengthSelected === 'Yes') {
191+
textArea.style.padding = optimalLineLengthPadding;
192+
} else {
193+
textArea.style.padding = editorConfig.defaultOptimalLineLengthPadding;
194+
}
195+
196+
setState('userChosenOptimalLineLengthSelected', optimalLineLengthSelected);
197+
})
198+
168199
notepad.resetPreferences.click(function () {
169200
if (selector().state.userChosenFontSize) {
170201
removeState('userChosenFontSize');
@@ -190,6 +221,11 @@ it's recommended that you take a backup of your notes more often using the
190221
removeState('userChosenWriteDirection');
191222
resetWriteDirection(editorConfig.defaultWriteDirection);
192223
}
224+
225+
if (selector().state.userChosenOptimalLineLengthSelected) {
226+
removeState('userChosenOptimalLineLengthSelected');
227+
resetOptimalLineLength(editorConfig.defaultOptimalLineLengthPadding, editorConfig.defaultOptimalLineLength);
228+
}
193229
});
194230

195231
// This changes the application's theme when

js/selector.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function selector() {
4646
wordCountContainer: selectByClassName('word-count-container'),
4747
keyboardShortcutsModal: selectById('keyboardShortcutsModal'),
4848
fullScreenButton: selectById('fullScreenButton'),
49+
optimalLineLength: selectById('optimalLineLength'),
4950
},
5051
state: {
5152
note: getState('note'),
@@ -57,6 +58,7 @@ function selector() {
5758
hasUserDismissedDonationPopup: getState('hasUserDismissedDonationPopup'),
5859
userChosenWordCountPillSelected: getState('userChosenWordCountPillSelected'),
5960
userChosenWriteDirection: getState('userChosenWriteDirection'),
61+
userChosenOptimalLineLengthSelected: getState('userChosenOptimalLineLengthSelected')
6062
},
6163
get,
6264
getState,

js/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ function resetWriteDirection(defaultWriteDirection) {
111111
$('#writeDirection').val(defaultWriteDirection);
112112
}
113113

114+
function resetOptimalLineLength(defaultEditorPadding, defaultOption) {
115+
const textArea = document.getElementById('note');
116+
textArea.style.padding = defaultEditorPadding;
117+
$('#optimalLineLength').val(defaultOption);
118+
}
119+
114120
function countWords(str) {
115121
return str.trim().split(/\s+/).length;
116122
}

0 commit comments

Comments
 (0)