1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Save scroll position in notes

This commit is contained in:
Laurent Cozic 2017-07-25 21:24:30 +01:00
parent d5e39d153f
commit ce6ca38fa0
4 changed files with 18 additions and 14 deletions

View File

@ -73,6 +73,8 @@ class NoteScreenComponent extends BaseScreenComponent {
isLoading: true,
};
this.bodyScrollTop_ = 0;
this.saveButtonHasBeenShown_ = false;
this.backHandler = () => {
@ -306,7 +308,7 @@ class NoteScreenComponent extends BaseScreenComponent {
return body;
}
function markdownToHtml(body, style) {
const markdownToHtml = (body, style) => {
// https://necolas.github.io/normalize.css/
const normalizeCss = `
html{line-height:1.15;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}
@ -374,11 +376,15 @@ class NoteScreenComponent extends BaseScreenComponent {
let elementId = 1;
while (html.indexOf('°°JOP°') >= 0) {
html = html.replace(/°°JOP°CHECKBOX°([A-Z]+)°(\d+)°°/, function(v, type, index) {
const js = "postMessage('checkboxclick_" + type + '_' + index + "'); this.textContent = this.textContent == '☐' ? '☑' : '☐';";
const js = "postMessage('checkboxclick:" + type + '_' + index + "'); this.textContent = this.textContent == '☐' ? '☑' : '☐'; return false;";
return '<a href="#" onclick="' + js + '" class="checkbox">' + (type == 'NOTICK' ? '☐' : '☑') + '</a>';
});
}
let scriptHtml = '<script>document.body.scrollTop = ' + this.bodyScrollTop_ + ';</script>';
html = '<body onscroll="postMessage(\'bodyscroll:\' + document.body.scrollTop);">' + html + scriptHtml + '</body>';
return html;
}
@ -391,12 +397,15 @@ class NoteScreenComponent extends BaseScreenComponent {
reg.logger().info('postMessage received: ' + msg);
if (msg.indexOf('checkboxclick_') === 0) {
msg = msg.split('_');
if (msg.indexOf('checkboxclick:') === 0) {
msg = msg.split(':');
let index = Number(msg[msg.length - 1]);
let currentState = msg[msg.length - 2]; // Not really needed but keep it anyway
const newBody = toggleTickAt(note.body, index);
this.saveOneProperty('body', newBody);
} else if (msg.indexOf('bodyscroll:') === 0) {
msg = msg.split(':');
this.bodyScrollTop_ = Number(msg[1]);
} else {
Linking.openURL(msg);
}

View File

@ -50,12 +50,7 @@ class NotesScreenComponent extends BaseScreenComponent {
parentId: parent.id,
});
if (source == props.notesSource) {
console.info('NO SOURCE CHAGNE');
console.info(source);
console.info(props.notesSource);
return;
}
if (source == props.notesSource) return;
let notes = [];
if (props.notesParentType == 'Folder') {
@ -103,7 +98,7 @@ class NotesScreenComponent extends BaseScreenComponent {
{ title: _('Edit notebook'), onPress: () => { this.editFolder_onPress(this.props.selectedFolderId); } },
];
} else {
return []; // TODO
return []; // For tags - TODO
}
}

View File

@ -113,6 +113,8 @@ class SearchScreenComponent extends BaseScreenComponent {
}
render() {
if (!this.isMounted_) return null;
return (
<View style={this.styles().screen}>
<ScreenHeader title={_('Search')}/>

View File

@ -208,10 +208,8 @@ class SideMenuContentComponent extends Component {
items.push(<View style={{ height: globalStyle.marginBottom }} key='bottom_padding_hack'/>);
// onLayout={(event) => this.onLayout(event)}
return (
<View style={{flex:1}}>
<View style={{flex:1, borderRightWidth: 1, borderRightColor: globalStyle.dividerColor }}>
<View style={{flexDirection:'row'}}>
<Image style={{flex:1, height: 150}} source={require('../images/SideMenuHeader.png')} />
</View>