mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-14 23:38:57 +00:00
add set_hash to Location
This commit is contained in:
@@ -16,7 +16,8 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const Uri = @import("std").Uri;
|
const std = @import("std");
|
||||||
|
const Uri = std.Uri;
|
||||||
|
|
||||||
const Page = @import("../page.zig").Page;
|
const Page = @import("../page.zig").Page;
|
||||||
const URL = @import("../url/url.zig").URL;
|
const URL = @import("../url/url.zig").URL;
|
||||||
@@ -42,6 +43,20 @@ pub const Location = struct {
|
|||||||
return page.navigateFromWebAPI(href, .{ .reason = .script }, .{ .push = null });
|
return page.navigateFromWebAPI(href, .{ .reason = .script }, .{ .push = null });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_hash(_: *const Location, hash: []const u8, page: *Page) !void {
|
||||||
|
const current_url = page.url.raw;
|
||||||
|
|
||||||
|
const base_without_hash = if (std.mem.indexOfScalar(u8, current_url, '#')) |pos|
|
||||||
|
current_url[0..pos]
|
||||||
|
else
|
||||||
|
current_url;
|
||||||
|
|
||||||
|
const normalized_hash = std.mem.trimStart(u8, hash, "#");
|
||||||
|
const new_url = try std.fmt.allocPrint(page.arena, "{s}#{s}", .{ base_without_hash, normalized_hash });
|
||||||
|
|
||||||
|
return page.navigateFromWebAPI(new_url, .{ .reason = .script }, .replace);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_protocol(self: *Location) []const u8 {
|
pub fn get_protocol(self: *Location) []const u8 {
|
||||||
return self.url.get_protocol();
|
return self.url.get_protocol();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user