Skip to content

Commit f84a60b

Browse files
committed
WIP (39)
1 parent 9eaa493 commit f84a60b

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

src/WinWebDiffLib/DiffHighlighter.hpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,11 @@ class DataForDiff
187187
const int s1 = size1 / sizeof(wchar_t);
188188
const int s2 = size2 / sizeof(wchar_t);
189189
int i1 = 0, i2 = 0;
190-
if (m_diffOptions.ignoreWhitespace == 2) {
190+
if (m_diffOptions.ignoreWhitespace == 2)
191+
{
191192
goto skip_ws;
192-
while (i1 < s1 && i2 < s2) {
193+
while (i1 < s1 && i2 < s2)
194+
{
193195
if (!match_a_wchar(l1[i1++], l2[i2++]))
194196
return false;
195197
skip_ws:
@@ -199,9 +201,12 @@ class DataForDiff
199201
i2++;
200202
}
201203
}
202-
else if (m_diffOptions.ignoreWhitespace == 1) {
203-
while (i1 < s1 && i2 < s2) {
204-
if (iswspace(l1[i1]) && iswspace(l2[i2])) {
204+
else if (m_diffOptions.ignoreWhitespace == 1)
205+
{
206+
while (i1 < s1 && i2 < s2)
207+
{
208+
if (iswspace(l1[i1]) && iswspace(l2[i2]))
209+
{
205210
/* Skip matching spaces and try again */
206211
while (i1 < s1 && iswspace(l1[i1]))
207212
i1++;
@@ -213,6 +218,14 @@ class DataForDiff
213218
return false;
214219
}
215220
}
221+
else
222+
{
223+
while (i1 < s1 && i2 < s2)
224+
{
225+
if (!match_a_wchar(l1[i1++], l2[i2++]))
226+
return false;
227+
}
228+
}
216229
return true;
217230
}
218231
unsigned long hash_a_wchar(wchar_t ch_) const
@@ -239,7 +252,7 @@ class DataForDiff
239252
}
240253
for (const wchar_t* ptr = begin; ptr < end; ptr++)
241254
{
242-
if (iswspace(*ptr))
255+
if (m_diffOptions.ignoreWhitespace != 0 && iswspace(*ptr))
243256
{
244257
while (ptr + 1 < end && iswspace(ptr[1]))
245258
ptr++;
@@ -569,11 +582,11 @@ namespace Comparer
569582
std::advance(it2, wd3.begin[2]);
570583
if (it2 == textBlocks[2].segments.end())
571584
return false;
572-
unsigned s0 = static_cast<unsigned>(textBlocks[0].segments[it0->second.begin].size);
573-
unsigned s2 = static_cast<unsigned>(textBlocks[2].segments[it2->second.begin].size);
585+
unsigned s0 = static_cast<unsigned>(textBlocks[0].segments[it0->second.begin].size) * sizeof(wchar_t);
586+
unsigned s2 = static_cast<unsigned>(textBlocks[2].segments[it2->second.begin].size) * sizeof(wchar_t);
574587
return data2.equals(
575-
reinterpret_cast<const char *>(textBlocks[0].textBlocks.data()) + it0->second.begin, s0,
576-
reinterpret_cast<const char *>(textBlocks[2].textBlocks.data()) + it2->second.begin, s2
588+
reinterpret_cast<const char *>(textBlocks[0].textBlocks.data() + it0->second.begin), s0,
589+
reinterpret_cast<const char *>(textBlocks[2].textBlocks.data() + it2->second.begin), s2
577590
);
578591
};
579592

src/WinWebDiffLib/WebDiffWindow.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ LR"(
689689
});
690690
});
691691
)";
692-
HRESULT hr = m_webWindow[pane].ExecuteScript(script,
692+
HRESULT hr = m_webWindow[pane].ExecuteScriptInAllFrames(script,
693693
Callback<IWebDiffCallback>([this, pane, callback2](const WebDiffCallbackResult& result) -> HRESULT
694694
{
695695
HRESULT hr = result.errorCode;

src/WinWebDiffLib/WebWindow.hpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,62 @@ class CWebWindow
972972
return hr;
973973
}
974974

975+
HRESULT executeScriptLoop(const wchar_t* script, IWebDiffCallback *callback,
976+
std::vector<wil::com_ptr<ICoreWebView2Frame>>::iterator it)
977+
{
978+
if (!GetActiveTab())
979+
return E_FAIL;
980+
if (it == GetActiveTab()->m_frames.end())
981+
{
982+
if (callback)
983+
callback->Invoke({ S_OK, nullptr });
984+
return S_OK;
985+
}
986+
ComPtr<IWebDiffCallback> callback2(callback);
987+
std::wstring script2(script);
988+
wil::com_ptr<ICoreWebView2Frame2> frame2 =
989+
it->try_query<ICoreWebView2Frame2>();
990+
if (!frame2)
991+
return E_FAIL;
992+
HRESULT hr = frame2->ExecuteScript(script,
993+
Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
994+
[this, it, callback2, script2](HRESULT errorCode, LPCWSTR resultObjectAsJson) -> HRESULT {
995+
HRESULT hr = errorCode;
996+
if (SUCCEEDED(hr))
997+
{
998+
std::vector<wil::com_ptr<ICoreWebView2Frame>>::iterator it2(it);
999+
++it2;
1000+
if (it2 != GetActiveTab()->m_frames.end())
1001+
hr = executeScriptLoop(script2.c_str(), callback2.Get(), it2);
1002+
else if (callback2)
1003+
callback2->Invoke({ hr, nullptr });
1004+
}
1005+
if (FAILED(hr) && callback2)
1006+
callback2->Invoke({ errorCode, resultObjectAsJson });
1007+
return S_OK;
1008+
}).Get());
1009+
return hr;
1010+
}
1011+
1012+
HRESULT ExecuteScriptInAllFrames(const wchar_t* script, IWebDiffCallback *callback)
1013+
{
1014+
if (!GetActiveWebView())
1015+
return E_FAIL;
1016+
ComPtr<IWebDiffCallback> callback2(callback);
1017+
std::wstring script2(script);
1018+
HRESULT hr = GetActiveWebView()->ExecuteScript(script,
1019+
Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
1020+
[this, callback2, script2](HRESULT errorCode, LPCWSTR resultObjectAsJson) -> HRESULT {
1021+
HRESULT hr = errorCode;
1022+
if (SUCCEEDED(hr))
1023+
hr = executeScriptLoop(script2.c_str(), callback2.Get(), GetActiveTab()->m_frames.begin());
1024+
if (FAILED(hr) && callback2)
1025+
callback2->Invoke({ errorCode, nullptr });
1026+
return S_OK;
1027+
}).Get());
1028+
return hr;
1029+
}
1030+
9751031
HRESULT ClearBrowsingData(IWebDiffWindow::BrowsingDataType dataKinds)
9761032
{
9771033
if (!GetActiveWebView())

src/WinWebDiffLib/WinWebDiffLib.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@
296296
</ItemGroup>
297297
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
298298
<ImportGroup Label="ExtensionTargets">
299-
<Import Project="$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
299+
<Import Project="$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
300300
<Import Project="$(SolutionDir)packages\tencent.rapidjson.1.1.1\build\tencent.rapidjson.targets" Condition="Exists('$(SolutionDir)packages\tencent.rapidjson.1.1.1\build\tencent.rapidjson.targets')" />
301301
<Import Project="$(SolutionDir)packages\Microsoft.Web.WebView2.1.0.1189-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Web.WebView2.1.0.1189-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
302302
</ImportGroup>
303303
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
304304
<PropertyGroup>
305305
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
306306
</PropertyGroup>
307-
<Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
307+
<Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
308308
<Error Condition="!Exists('$(SolutionDir)packages\tencent.rapidjson.1.1.1\build\tencent.rapidjson.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\tencent.rapidjson.1.1.1\build\tencent.rapidjson.targets'))" />
309309
<Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Web.WebView2.1.0.1189-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Web.WebView2.1.0.1189-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
310310
</Target>

src/WinWebDiffLib/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Microsoft.Web.WebView2" version="1.0.1189-prerelease" targetFramework="native" />
4-
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
4+
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.191107.2" targetFramework="native" />
55
<package id="tencent.rapidjson" version="1.1.1" targetFramework="native" />
66
</packages>

0 commit comments

Comments
 (0)