Skip to content

Commit

Permalink
解决预览页面关闭重新打开不显示内容
Browse files Browse the repository at this point in the history
  • Loading branch information
naosense committed Aug 27, 2018
1 parent a668086 commit 540a2aa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions autoload/mpsync.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ function! s:open()
execute "silent !\"" . g:markdown_preview_sync_firefox_path . "\" http://127.0.0.1:" . g:markdown_preview_sync_port . "/index"
endif
endif

python <<EOF
path = vim.eval('expand("%:p")')
java_vim_bridge.open(path)
EOF
endfunction

function! s:sync()
Expand Down
4 changes: 4 additions & 0 deletions autoload/python/java_vim_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def _connect(port, theme):
s.send('start' + SEP + str(port) + SEP + theme + EOF)


def open(path):
s.send('open' + SEP + path + EOF)


def sync(path, content, bottom):
s.send('sync' + SEP + path + SEP + content + SEP + str(bottom) + EOF)

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/pingao/server/SocketServer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pingao.server;

import com.pingao.utils.FileUtils;
import com.pingao.utils.JSoupUtils;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
Expand Down Expand Up @@ -63,6 +64,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
server.setTheme(data[2]);
server.start(Integer.parseInt(data[1]));
break;
case "open":
JSoupUtils.removeCache(data[1]);
break;
case "sync":
server.broadcast("sync", data[1], data[2], Integer.parseInt(data[3]));
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.pingao.server;

import com.pingao.utils.JSoupUtils;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
Expand Down Expand Up @@ -28,8 +27,6 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
@Override
public void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) {
msg.retain();
if (msg.text().contains("close")) {
JSoupUtils.removeCache(msg.text().split(",")[1]);
}
Logger.info("Received msg {}", msg.text());
}
}
5 changes: 0 additions & 5 deletions src/main/webapp/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ $(function () {
}


$(window).bind('beforeunload', function () {
ws.send('close,' + $('#path').val());
});


self.mark_line = function (line) {
if (ws !== null) {
ws.send(line);
Expand Down

0 comments on commit 540a2aa

Please # to comment.